-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Featire request: Allow unpacking of type variable bound to typed dict #5069
Comments
Ultimately, I'd like something like this to work if possible? from typing import Generic, Unpack
from typing_extensions import TypedDict, TypeVar, override
class EmptyDict(TypedDict, total=True):
pass
Extra = TypeVar('Extra', bound=TypedDict, default=EmptyDict)
class C(Generic[Extra]):
def f(self, **kwargs: Unpack[Extra]) -> None: # error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues)
pass
class D(C):
@override
def f(self) -> None: # error: Method "f" overrides class "C" in an incompatible manner
pass
class HasName(TypedDict, total=True):
name: str
class E(C[HasName]):
@override
def f(self, name: str) -> None:
print(name)
D().f()
E().f("a") |
This would require an extension to the Python type system, so it is best discussed in the python/typing forum. It would probably require a new PEP or an extension to PEP 692. There are two extensions that would be required:
I'm going to close this enhancement request for now. If you want to get feedback from the broader typing community about these changes/extensions, please open an issue in python/typing. |
@erictraut Okay, many thanks for your thorough explanation as always! |
The text was updated successfully, but these errors were encountered: