Skip to content

Conversation

@henryiii
Copy link
Contributor

@henryiii henryiii commented Nov 25, 2025

Some minor cleanup before #988 (commit also present there).

  • A few more comments, broke up the local version line into several lines like the others
  • Inside [], no need to escape .
  • Used fullmatch (3.4+) instead of search + anchors

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii henryiii merged commit 6782eab into pypa:main Nov 25, 2025
40 checks passed
@henryiii henryiii deleted the henryiii/chore/regex branch November 25, 2025 18:23
"""

_regex = re.compile(r"^\s*" + VERSION_PATTERN + r"\s*$", re.VERBOSE | re.IGNORECASE)
_regex = re.compile(r"\s*" + VERSION_PATTERN + r"\s*", re.VERBOSE | re.IGNORECASE)
Copy link
Member

Choose a reason for hiding this comment

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

Do the anchors hurt anything if they are used with fullmatch? Just thinking in case someone changes what method is used and don't realize the regex is tailored to fullmatch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can test. This doesn't affect the public string, just ._regex. Those were not the right anchors away, /A and /Z are more technically correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem to be about 1% slower with the anchors. Since the public string VERSION_PATTERN is the same, I think it's fine to change the internal ._regex slightly like this? That's what the _ at the front means, after all. :)

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.

2 participants