Closed david-zwicker closed 3 months ago
you're on an old mypy
I'm on mypy 1.11.1 (compiled: yes)
, which I believe is the latest one.
show your output and full code?
I cannot fully isolate the problem, but it appears in the code base of py-pde
. I'll try to come up with a minimal example and post it here!
please start with that next time instead of wasting my time!
I have the same or a similar issue. I ran pyupgrade --py310-plus myfile.py
on the following code
from __future__ import annotations
from collections.abc import Generator
def generator() -> Generator[int, None, None]:
yield 1
and it gets shortened to:
from __future__ import annotations
from collections.abc import Generator
def generator() -> Generator[int]:
yield 1
My version of pyupgrade is 3.17.0
Without the from __future__ import annotations
line the Generator type hint is not shortened.
I think
--py310-plus
flag. The CPython docs mention the possibility for shortening only since Python 3.13: link. The current mypy stable (1.11.2) docs do not mention the shortening: link, also not the typing documentation (as of now).you're wrong. mypy accepts it just fine with the import just like all other improvements.
where are you seeing otherwise?
it's irrelevant if a code optimization works with one specific tool read the CPython doc!
it's legitimate to write Python 3.10 code, it's legitimate to write 3.10 code with the annotations import, and it's legitimate to write the type hints in the same 3.10-way
when I run pyupgrade --py310-plus
apparently the "3.10 type hints" are upgraded to 3.13 type hints (!), which is surprising behavior - it'd be better to change that
at least the behavior is somehow documented: https://github.com/asottile/pyupgrade?tab=readme-ov-file#pep-696-typevar-defaults
and there's remedy with --keep-runtime-typing
in this case
read the pyupgrade doc!
you still haven't demonstrated any breakage so I'm assuming you're just a troll
pyupgrade
turns the following codeinto
which is wrong according to
mypy
. I believepyupgrade
should keep the three-argument version.