Closed
Description
Bug report
Bug description:
from typing import NotRequired, Required, TypedDict
class A(TypedDict):
a: NotRequired[int]
b: Required[int]
class B(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 of PEP-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