-
Notifications
You must be signed in to change notification settings - Fork 78
chore: avoid formatting code with mypy comments #2554
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ohmayr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements a preventative measure against potential issues arising from code formatters, such as Black, reformatting lines that contain specific Python comments like Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds # fmt: skip comments to lines containing # type: ignore or # pragma: NO COVER across various Jinja2 templates. This is a good maintenance change to prevent code formatters from breaking these important comments in the generated Python code. The changes are consistent and correctly applied to the generator templates. I've made a few suggestions to remove some explanatory comments from the test templates, as they would add unnecessary noise to the generated code.
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
868fe4d to
aa669b2
Compare
| api_core.check_python_version("{{package_path}}") # type: ignore | ||
| api_core.check_dependency_versions("{{package_path}}") # type: ignore | ||
| else: # pragma: NO COVER | ||
| {# Add `# pragma: NO COVER` to keep `# pragma: NO COVER` on the same line #} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this should say Add # fmt: skip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one needed? It's a short line. What does the formatter try to do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2
Outdated
Show resolved
Hide resolved
| response = continuation(client_call_details, request) | ||
| if logging_enabled: # pragma: NO COVER | ||
| {# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #} | ||
| if logging_enabled: # pragma: NO COVER # fmt: skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the formatter move this line?
7bf0af3 to
22f7a2f
Compare
daniel-sanche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with adding fmt: skip if needed, but in that case, we should try to manually format the line first, so we're not left with any excessively long lines
Some of them seem unnecessary to me though. Were all of these lines giving problems? Or did you just add fmt: skip to every line that contained another annotation?
| """ | ||
| return {{ service.client_name }}.from_service_account_file.__func__({{ service.async_client_name }}, filename, *args, **kwargs) # type: ignore | ||
| {# Add `# fmt: skip` to keep `# type: ignore` on the same line #} | ||
| return {{ service.client_name }}.from_service_account_file.__func__({{ service.async_client_name }}, filename, *args, **kwargs) # type: ignore # fmt: skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be broken up?
| from importlib import metadata | ||
| else: # pragma: NO COVER | ||
| {# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #} | ||
| else: # pragma: NO COVER # fmt: skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused why the skip tag is needed here. Is ruff doing anything to this line? Or is this just in case?
|
|
||
| if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER | ||
| {# Add `# fmt: skip` to keep `# pragma: NO COVER` on the same line #} | ||
| if hasattr(api_core, "check_python_version") and hasattr(api_core, "check_dependency_versions"): # pragma: NO COVER # fmt: skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of skipping the formatting, can this be broken into multiple lines? This is 129 characters, so it will stand out quite a bit
Adds fmt: skip to lines containing
pragma: NO COVERandtype: ignore. This prevents the formatter from wrapping these comments to new lines during the migration from Black to Ruff, ensuring we don't get any mypy failures. These can be removed whenever the inlinepragma: NO COVERandtype: ignoreare fixed or removed.