Presence of future annotation import causes improper application of PEP 604 for Python 3.7
See original GitHub issueGiven these file contents:
# foo.py
from __future__ import annotations
from typing import Optional
def some_function(some_arg: Optional[str] = None):
...
Running the following command:
$ pyupgrade --py37-plus
Rewrites the file contents to:
# foo.py
from __future__ import annotations
from typing import Optional
def some_function(some_arg: str | None = None):
...
Which to my understanding is not valid before Python 3.10. Note that if the from __future__ import annotations
line is not present initially, the file remains unchanged.
This is the case on at least versions 2.29.1
and 2.31.0
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Support PEP 604 -- Allow writing union types as X | Y
Properly take into account the presence of from __future__ import annotations . Ensure that the warnings about the syntax remain in earlier versions...
Read more >What, within __future__, made list[str] start working on 3.7?
I understand that PEP 585 lets us type hint the standard collection objects ... from __future__ import annotations x: list[str] = ["a", "b"]....
Read more >Python 3.7: from __future__ import annotations #2950 - GitHub
Hi, I'm on Windows 10, Python 3.7.1, Cython 0.29.7. I have some pure python code that I wanted to compile that uses from...
Read more >Mypy Documentation
Mypy is a static type checker for Python. Type checkers help ensure that you're using variables and functions in your code correctly.
Read more >Can't import annotations from __future__ - Stack Overflow
If so, then the error happens because according to PEP-563 the import of __future__ annotations is available starting with Python 3.7 .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it is valid if you have
from __future__ import annotations
:That’s right, it’s OR. I think this was brought up before but the maintainer thought it was clear enough as it is
you don’t respect it though, you’re here making noise and telling people how to use the tool