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

Add UP and FA rules to ruff #3155

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Kludex
Copy link
Contributor

@Kludex Kludex commented Dec 27, 2024

To avoid misunderstandings like #3118, we can enforce the from __future__ import annotations.

This PR only adds the rules and apply changes to pass the pipeline.

@Kludex Kludex requested a review from a team as a code owner December 27, 2024 09:45
Comment on lines +23 to +24
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
"FA" # https://docs.astral.sh/ruff/rules/#flake8-future-annotations-fa
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those two are the additions from this PR.

@Kludex Kludex changed the title enforce future annotations Add UP and FA rules to ruff Dec 27, 2024
Copy link

@Viicos Viicos left a comment

Choose a reason for hiding this comment

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

Assuming otel does not make use of any types at runtime, this should be ok

@@ -34,8 +36,8 @@ class AiopgIntegration(DatabaseApiIntegration):
async def wrapped_connection(
self,
connect_method: typing.Callable[..., typing.Any],
args: typing.Tuple[typing.Any, typing.Any],
kwargs: typing.Dict[typing.Any, typing.Any],
args: tuple[typing.Any, typing.Any],
Copy link

Choose a reason for hiding this comment

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

Maybe next step would be to standardize typing imports (e.g. import typing; var: typing.Any vs from typing import Any; var: Any), and also how typing_extensions should be used. I usually see two patterns:

  • Unconditionally import from typing_extensions if it is introduced in a newer Python version. We need to make sure these imports are updated whenever a Python version is dropped.
  • Define a typing compat module, where new typing constructs are conditionally imported from typing or typing_extensions. Easier to update when a Python version is dropped.

@Kludex
Copy link
Contributor Author

Kludex commented Jan 2, 2025

If people give me their thumbs up, I'm happy to rebase this.

Copy link
Contributor

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

I love this

@Kludex
Copy link
Contributor Author

Kludex commented Jan 3, 2025

If any changelog is needed, please let me know. :)

@Kludex Kludex force-pushed the enforce-future-annotations branch from 78526e4 to be8ab2f Compare January 3, 2025 13:20
Copy link
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

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

Maybe we can start using .git-blame-ignore-revs for ruff changes that touches several files

@Kludex Kludex force-pushed the enforce-future-annotations branch from be8ab2f to 4a06c4d Compare January 3, 2025 13:55
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.