-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working
Description
Describe the bug
Assume there is a TypeVar A that depends on another TypeVar B for its default, and that there is a class generic over A and B. Any method using B but not A for annotations will show an error saying that the default type refers to a type parameter not in scope. I would've guessed that in a class context, A would be in scope, even if it isn't being used at the function level for a particular method.
Code or Screenshots
from typing import Generic, Self, TypeVar, overload
A = TypeVar("A", default=int)
B = TypeVar("B", default=A)
class Test(Generic[A, B]):
@property
def start(self) -> A: ...
@property
def stop(self) -> B: ... # error
# Type parameter "B" has a default type that refers to one or more type variables that are out of scope
# Type variable "A" is not in scope
@overload
def __new__(cls, stop: B, /) -> Self: ... # error
# Type parameter "B" has a default type that refers to one or more type variables that are out of scope
# Type variable "A" is not in scope
@overload
def __new__(cls, start: A, stop: B, /) -> Self: ...
VS Code extension or command-line
command-line: pyright 1.1.355
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionbugSomething isn't workingSomething isn't working