Skip to content

Conversation

xcrong
Copy link
Contributor

@xcrong xcrong commented Jul 23, 2025

Beanie's Regex Class can use re.Pattern[str] as pattern. In the background, bson.regex.Regex 's .from_native method support it. So I add it to type hint.

In exist tests, we also can see that:

async def test_encode_regex():
raw_regex = r"^AA.*CC$"
case_sensitive_regex = re.compile(raw_regex)
case_insensitive_regex = re.compile(raw_regex, re.I)
assert isinstance(Encoder().encode(case_sensitive_regex), Regex)
assert isinstance(Encoder().encode(case_insensitive_regex), Regex)

image

CAPITAINMARVEL
CAPITAINMARVEL previously approved these changes Aug 25, 2025
Copy link
Contributor

@CAPITAINMARVEL CAPITAINMARVEL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CAPITAINMARVEL CAPITAINMARVEL requested a review from a team August 25, 2025 10:37
@staticxterm staticxterm changed the title fix: imcomplete type hint for Regex's pattern. fix: incomplete type hint for Regex pattern Aug 25, 2025
staticxterm
staticxterm previously approved these changes Aug 25, 2025
@staticxterm staticxterm requested a review from a team August 25, 2025 10:38
@CAPITAINMARVEL CAPITAINMARVEL dismissed their stale review August 25, 2025 11:23

added suggestion

Co-authored-by: ᑕᗩᑭTᗩIᑎᗰᗩᖇᐯᗴᒪ <91954476+CAPITAINMARVEL@users.noreply.github.com>
Co-authored-by: Virtual1ty <staticxterm@users.noreply.github.com>
xcrong and others added 2 commits August 25, 2025 22:48
Co-authored-by: ᑕᗩᑭTᗩIᑎᗰᗩᖇᐯᗴᒪ <91954476+CAPITAINMARVEL@users.noreply.github.com>
Copy link
Contributor Author

@xcrong xcrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, I can't understand the change, should we change it to:

        ...
        pattern: Union[AnyStr, re.Pattern[AnyStr]],
        options: Optional[str] = None,
        ...

@CAPITAINMARVEL
Copy link
Contributor

hey, I can't understand the change, should we change it to:

        ...
        pattern: Union[AnyStr, re.Pattern[AnyStr]],
        options: Optional[str] = None,
        ...

No because pymongo will raise an error ($regex has to be a string)
pymongo can only accept a string or a re.Pattern

CAPITAINMARVEL
CAPITAINMARVEL previously approved these changes Aug 26, 2025
@CAPITAINMARVEL CAPITAINMARVEL requested a review from a team August 26, 2025 09:36
fixed my typo and mypy
Copy link
Contributor

@CAPITAINMARVEL CAPITAINMARVEL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@CAPITAINMARVEL CAPITAINMARVEL requested a review from 07pepa August 26, 2025 10:14
@CAPITAINMARVEL CAPITAINMARVEL requested review from a team and Riverfount August 26, 2025 10:14
Copy link
Contributor

@staticxterm staticxterm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it took us a while, but we finally got there. Looks good to me now.

@staticxterm staticxterm requested a review from a team August 26, 2025 10:26
@07pepa 07pepa merged commit 415c319 into BeanieODM:main Aug 30, 2025
101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants