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

Use from __future__ import annotations across all code #1336

Open
dimaqq opened this issue Aug 26, 2024 · 5 comments
Open

Use from __future__ import annotations across all code #1336

dimaqq opened this issue Aug 26, 2024 · 5 comments

Comments

@dimaqq
Copy link
Contributor

dimaqq commented Aug 26, 2024

Current status: discussion

from __future__ import annotations means we don't have to quote many type hints:

-    def from_dict(cls, d: '_SystemInfoDict') -> 'SystemInfo':
+    def from_dict(cls, d: _SystemInfoDict) -> SystemInfo:

Which originally stems from this:

if TYPE_CHECKING:
    from typing_extensions import NotRequired

I would argue that we should use new (py 3.10+) type hinting machinery and write our code almost as if it were for py 3.10+ only.

@tonyandrewmeyer
Copy link
Contributor

In general, I'm in favour of using __future__ imports as early as possible.

My one concern here is that it's uncertain when the behaviour will become the default, or if it will change before that happens. However, my knowledge here is very limited (reading over the docs just now, and listing to a few podcast episodes talking about this quite some time back that I only partially recall). I'm not even sure what the current situation is - the docs link to the 3.11 postponement but not to anything about 3.12 or 3.13.

@tonyandrewmeyer
Copy link
Contributor

With from __future__ import annotations we can change our types to be in the form a: int | str | None = 42 rather than a: Optional[Union[int, str]] = 42, and still support Python 3.8, right? I didn't realise this before today. If that is correct, then I'm 💯 in favour of this, even with the ultimate status of the PEP still in question.

@benhoyt
Copy link
Collaborator

benhoyt commented Sep 24, 2024

Ooh, yes, if what Tony's saying is the case, I'd be in favour of this too. Let's confirm that and then do this. Can Pyright or Ruff or something automate the conversion?

@tonyandrewmeyer
Copy link
Contributor

Can Pyright or Ruff or something automate the conversion?

pyupgrade can. Ruff has pyupgrade's checks, so maybe it also can?

@tonyandrewmeyer
Copy link
Contributor

See also canonical/ops-scenario#203 for this being done in Scenario.

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

No branches or pull requests

3 participants