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

Fix formats in fastapi/utils #5075

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

LeSZ0
Copy link

@LeSZ0 LeSZ0 commented Jun 24, 2022

Fix & improve formats in utils

@codecov
Copy link

codecov bot commented Jun 24, 2022

Codecov Report

Merging #5075 (d84df5c) into master (f8c875b) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #5075   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          532       532           
  Lines        13672     13670    -2     
=========================================
- Hits         13672     13670    -2     
Impacted Files Coverage Δ
fastapi/dependencies/utils.py 100.00% <100.00%> (ø)
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 f8c875b...d84df5c. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 0295250 at: https://62b5c5ec9920ad03052f547d--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit 66a7b7b at: https://62b5cde13f6bab09bf7e0273--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.

I like the changes to the string formatting (e.g using f"blaat{var}" as it is more widely used in other parts of FastAPI. There is one more instance I found you could add:

model_name = "Body_" + name

However, the changes on line 54-56 are less explicit than what they are replacing. I find it better to set variables explicitly rather than inline when passing them as parameters in another method call (which you are proposing). The same goes for line 172/173; I like it better on two lines than in a single statement in a for-statement.

fastapi/utils.py Outdated Show resolved Hide resolved
fastapi/utils.py Outdated
return operation_id


def generate_unique_id(route: "APIRoute") -> str:
operation_id = route.name + route.path_format
operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
assert route.methods
operation_id = operation_id + "_" + list(route.methods)[0].lower()
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is proper, it is in line with other LoC in this package so I would be supporting this.

Copy link

Choose a reason for hiding this comment

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

re.compile("[^0-9a-zA-Z_]") or re.compile("\W") for speedup

@@ -134,15 +132,15 @@ def generate_operation_id_for_path(
)
operation_id = name + path
operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
operation_id = operation_id + "_" + method.lower()
operation_id = f"{operation_id}_{method.lower()}"
Copy link
Contributor

Choose a reason for hiding this comment

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

And therefor, I would also be supporting it here.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 98e137a at: https://62bc72dd7b439700aec3cff2--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit d84df5c at: https://62bda3a4f0a8b20da4ff294c--fastapi.netlify.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants