Forward references to type variables behave strangely in fine grained
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with the fine-grained test case named testForwardTypeVar and reproduce the two runs using the a.py and b.py inputs in the report. Investigate how the forward reference to T is processed across runs; done means the diagnostics remain consistent or the intended handling of invalid forward references is documented and tested.
Written by the indexing model from the issue text.
Description
This is similar to #4615
In the situation with a forward reference to type variable, first and second run in fine grained mode give different results:
[case testForwardTypeVar]
import a
[file a.py]
from typing import Generic, TypeVar
import b
def f() -> None:
class C(Generic[T]): pass
x: C[int]
T = TypeVar('T')
[file b.py]
y = 0
[file b.py.2]
y = ''
[out]
a.py:5: error: Free type variable expected in Generic[...]
a.py:6: error: "C" expects no type arguments, but 1 given
==
The errors don't appear in the second run. A possible solution is to allow forward references to type variables, although it is quite hard.
A general comment about fine grained mode is that it will be probably hard to support detection of invalid forward references (see for example https://github.com/python/mypy/issues/2400), the error would depend on the order of targets in file.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
fix: inaccuracy ⚠️
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
uabrc/uabrc.github.io#1255 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ethereum-optimism/factory#64 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
duckdb/duckdb-python#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Qiskit/qiskit-addon-sqd#376 ·