Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻ Simplify internal RegEx in fastapi/utils.py #5057

Merged
merged 2 commits into from Aug 26, 2022

Conversation

pylounge
Copy link
Contributor

Replace regex for simple

@codecov
Copy link

codecov bot commented Jun 20, 2022

Codecov Report

Merging #5057 (9786b7f) into master (1876ebc) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #5057   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          532       532           
  Lines        13672     13672           
=========================================
  Hits         13672     13672           
Impacted Files Coverage Δ
fastapi/utils.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1876ebc...9786b7f. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 9786b7f at: https://62afeb41aa8c7445d0b7c931--fastapi.netlify.app

Copy link
Contributor

@JarroVGIT JarroVGIT left a comment

Choose a reason for hiding this comment

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

Agree, \W is the equivalent of [^a-zA-Z0-9_] and is more elegant.

@lucaswiman
Copy link

Agree, \W is the equivalent of [^a-zA-Z0-9_] and is more elegant.

No, that's not true. It's equivalent to [^\w], which is a wider range of characters that just those. For example:

>>> import re
>>> re.match(r'\W', 'ü')
>>> re.match(r'\w', 'ü')
<re.Match object; span=(0, 1), match='ü'>

This change may lead to better support for languages with non-ASCII characters, but it's not precisely equivalent to the old code.

@JarroVGIT
Copy link
Contributor

Agree, \W is the equivalent of [^a-zA-Z0-9_] and is more elegant.

No, that's not true. It's equivalent to [^\w], which is a wider range of characters that just those. For example:

>>> import re
>>> re.match(r'\W', 'ü')
>>> re.match(r'\w', 'ü')
<re.Match object; span=(0, 1), match='ü'>

This change may lead to better support for languages with non-ASCII characters, but it's not precisely equivalent to the old code.

I stand corrected. I took my information from regex101.com, and you are completely right.

If this changes the behaviour, then I would expect a test case that would illustrate the exact intended behaviour.

@tiangolo tiangolo changed the title Replace regex ♻ Simplify internal RegEx in fastapi/utils.py Aug 26, 2022
@tiangolo
Copy link
Owner

Great, thanks @pylounge! 🍰

@tiangolo tiangolo merged commit dc10b81 into tiangolo:master Aug 26, 2022
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.

None yet

4 participants