Skip to content

Conversation

@ohmayr
Copy link
Contributor

@ohmayr ohmayr commented Jan 31, 2026

Adds fmt: skip to lines containing pragma: NO COVER and type: 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 inline pragma: NO COVER and type: ignore are fixed or removed.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jan 31, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 # type: ignore or # pragma: NO COVER. By adding # fmt: skip to these lines within the Jinja2 templates, the generated Python code will explicitly instruct formatters to bypass those lines, thereby safeguarding the integrity and effectiveness of these critical comments. This change enhances the robustness of the generated code against formatting tools.

Highlights

  • Preventing Formatter Conflicts: Introduced # fmt: skip comments to lines containing # type: ignore or # pragma: NO COVER to prevent automatic code formatters from reformatting these lines.
  • Maintaining Comment Integrity: Ensures that mypy type-checking exclusions and code coverage exclusions remain on the same line as the code they apply to, preserving their intended functionality.
  • Template-Wide Application: Applied these changes across numerous Jinja2 templates (.j2 files) to affect generated Python code consistently.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@ohmayr ohmayr force-pushed the update-templates-to-ignore-templates branch from 868fe4d to aa669b2 Compare January 31, 2026 00:25
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jan 31, 2026
@ohmayr ohmayr marked this pull request as ready for review January 31, 2026 00:26
@ohmayr ohmayr requested a review from a team as a code owner January 31, 2026 00:26
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 #}
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

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
Copy link
Contributor

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?

@ohmayr ohmayr force-pushed the update-templates-to-ignore-templates branch from 7bf0af3 to 22f7a2f Compare January 31, 2026 00:57
Copy link
Contributor

@daniel-sanche daniel-sanche left a 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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants