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

Forward references to type variables behave strangely in fine grained #4762

Open
ilevkivskyi opened this issue Mar 20, 2018 · 0 comments
Open

Comments

@ilevkivskyi
Copy link
Member

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 #2400), the error would depend on the order of targets in file.

irusland added a commit to Tinkoff/invest-python that referenced this issue Jan 23, 2022
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

1 participant