Skip to content

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

Merged
tiangolo merged 2 commits intofastapi:masterfrom
pylounge:pylounge-utils
Aug 26, 2022
Merged

♻ Simplify internal RegEx in fastapi/utils.py#5057
tiangolo merged 2 commits intofastapi:masterfrom
pylounge:pylounge-utils

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
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.

@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
Member

Great, thanks @pylounge! 🍰

@tiangolo tiangolo merged commit dc10b81 into fastapi: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.

4 participants