Describe the bug
In strict mode, method access on a generic class (not an instance) gives a type is partially unknown error. The problem arose for me calling __init__ of a generic superclass (example 1 below). But I found that it is not specific to __init__ - it happens with any method.
I tried supply the type as an argument i.e A[int].__init__. This passes type checking but doesn't actually call the method at runtime.
I would expect a (unbound) method to be treated similarly to a generic (non-method) function i.e. using the @ notation. My example 2 below illustrates the point.
Code or Screenshots
Example 1 - calling superclass __init__:
from typing import Generic, TypeVar
T = TypeVar("T")
class A(Generic[T]):
def __init__(self, x:T):
...
class B(A[int]):
def __init__(self, x:int):
A.__init__(self, x) # Type of "__init__" is partially unknown
(Pyright playgrround)
Example 2 - inconsistency with (non-method) generic function:
from typing import Generic, TypeVar
T = TypeVar("T")
def g(a: T, x:T):
...
# Revealed type is "(variable) def g2(a: T@g, x: T@g) -> None".
g2 = g
class A(Generic[T]):
def f(self, x: T):
...
# Partially unknown type.
# I would expect revealed type to be something like "f(self: A[T@f], x: T@f)".
f = A.f
Playground
VS Code extension or command-line
Pyright playgrround, strict mode, latest version.
Describe the bug
In strict mode, method access on a generic class (not an instance) gives a type is partially unknown error. The problem arose for me calling
__init__of a generic superclass (example 1 below). But I found that it is not specific to__init__- it happens with any method.I tried supply the type as an argument i.e
A[int].__init__. This passes type checking but doesn't actually call the method at runtime.I would expect a (unbound) method to be treated similarly to a generic (non-method) function i.e. using the @ notation. My example 2 below illustrates the point.
Code or Screenshots
Example 1 - calling superclass
__init__:(Pyright playgrround)
Example 2 - inconsistency with (non-method) generic function:
Playground
VS Code extension or command-line
Pyright playgrround, strict mode, latest version.