Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
fromtypingimportNotRequired,Required,TypedDictclassA(TypedDict):a:NotRequired[int]b:Required[int]classB(A):a:Required[int]b:NotRequired[int]print(B.__required_keys__)print(B.__optional_keys__)
This will print (tried on 3.11 and current-ish main):
frozenset({'b', 'a'})frozenset({'b', 'a'})But obviously, a single key should only be either Required or NotRequired, not both. The child class's version should prevail.
@alicederyn and I discovered this while discussing the implementation ofPEP-705 (python/typing_extensions#284). cc@davidfstr for PEP 655.
I also see some problems with how type checkers handle this case, but i'll post about that separately.
CPython versions tested on:
3.11, CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict #112512
- [3.12] gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict (GH-112512) #112530
- [3.11] gh-112509: Fix keys being present in both required_keys and optional_keys in TypedDict (GH-112512) #112531