You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In .pyi stub files, the spec mandates type-checkers to recognise forward references in annotation expressions without string-quoting. It is however silent about value expressions, but in mypy I've used symbols defined later in a stub file in a value context before without any issues, except recently when hitting the following example:
# stub.pyifromtyping_extensionsimportGeneric, TypeVarR=TypeVar("R")
T=TypeVar("T")
classA(Generic[R]):
var=B[R]() # E: "R" is a type variable and only valid in type contextclassB(Generic[T]): ...
Expected Behavior
Either:
no errors, or
mypy doesn't support forward references in value contexts for stub files, and this emits a used-before-def error at B[R]().