Skip to content

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

Open
@ilevkivskyi

Description

@ilevkivskyi

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions