pytype
pytype copied to clipboard
typing_extensions.TypedDict cannot inherit from a non-TypedDict class, but only sometimes
Hey folks, I'm getting some very inconsistent behavior with the following code:
from __future__ import annotations
from typing import Callable, Generic, TypeVar
from typing_extensions import TypedDict
T = TypeVar('T')
class Foo(TypedDict, Generic[T], total=False):
a: Callable[[int], T]
This will fail with the following:
File "", line 10, in <module>: Invalid base class: Generic[T] [base-class-error]
TypedDict Foo cannot inherit from a non-TypedDict class.
For more details, see https://google.github.io/pytype/errors.html#base-class-error
however, replacing the def for Foo with the following succeeds:
class Foo(TypedDict, Generic[T], total=False):
a: T
the typing_extensions version of TypedDict does explicitly support using Generics, and it seems like pytype follows that rule, but inconsistently
When I look at the saved pyi files in .pytype/pyi/<path/to/foo> I see the following error, not sure if this is helpful:
# pytype.pytd.visitors.ContainerError: Class Foo is not a container