-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed as not planned
Description
When mypy is run on the following code:
from typing import Any, Generic, TypeVar
T = TypeVar('T', bound=int)
class C(Generic[T]):
x: T
c: C[Any] = C()
c.x = 123
c.x = 'abc'
It will not report any errors. However, since T
has int
as a bound, assigning a string to x
should be considered invalid even if we don't know the exact type of x
.
It seems that when Any
is substituted for the type argument of C
, the knowledge of the bound is lost. Perhaps AnyType
could be given a bound, object
by default, to restrict which types Any
can represent in a particular context.
Kangaroux, BvB93, esoma and sg495