Feature request: Allow unpacking of type variable bound to typed dict
Open
Nobody has claimed this yet.
topic: feature
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 302
- Avg merge
- 23h
- Merged PRs (30d)
- 8
Description
I'd like to have a family of classes where overrides have additional parameters to various methods:
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: # This doesn't work.
print(name)
D().f()
E().f("a")
See @erictraut's instructive comment on the issue here.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Python reproducer in the issue and read Eric Traut's linked comment for the existing discussion. Clarify the intended semantics for unpacking a type variable bound to a TypedDict and for the shown overrides; done means the behavior and typing rules are specified clearly enough to guide an implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100