A generic version of typing.TypedDict.
This would allow for people to make there own typed Mappings, it would desugar to a series of overloads on __getitem__ and get
class MyMapping(MultiDict, TypedMapping):
foo: int
bar: NotRequired[str]A type checker should see this as (but in valid typed python)
class MyMapping(MultiDict):
def __getitem__(self, key: "foo") -> int: ...
def __getitem__(self, key: "bar") -> str | Never: ...
def get(self, key: "foo", default: Never = ...) -> int: ...
def get(self, key: "bar", default: T = ...) -> str | T: ...This would make this whole file not a big # type: ignore along with not working on mypy.
TypedDict would be defined as
class TypedDict(Mapping[str, Any], TypedMapping):
passA generic version of typing.Annotated. It erases its first X number of types at runtime using Varidic types.
Annotated would be defined like so
class Annotated(PhantomType[T, *Ts]):
__metadata__: tuple[*Ts]This is an exclusion type and would have to be added after an intersection type.
def ask_for_input(to_print: str & ~Literal[""]) -> str: ...
def fn(x: ~Literal[None]): ...
class Foo:
def __eq__(self, other: ~Self) -> Literal[False]: ...
def __eq__(self, other: Self) -> bool: ...
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and ...type import typing
class Foo:
bar: typing.Dict # for lack of a better symbol coming to mind
Foo.__annotations__ # calls __annotate__() and annotate can lazyily get the typing import