pytype icon indicating copy to clipboard operation
pytype copied to clipboard

typing_extensions.TypedDict cannot inherit from a non-TypedDict class, but only sometimes

Open theahura opened this issue 3 years ago • 1 comments

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

theahura avatar Jul 20 '22 22:07 theahura

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

theahura avatar Jul 21 '22 05:07 theahura