Looks great! Some feedback:
- PEP readers who are not typing experts may appreciate adding a paragraph like the following to the end of §“Abstract”, so that they don’t need to read further: (I added a similar paragraph in PEP 655 based on feedback received then.)
This PEP makes no Python grammar changes. Correct usage of read-only keys of TypedDicts is intended to be enforced only by static type checkers and need not be enforced by Python itself at runtime.
-
§“Motivation” is quite clear.
§“Updating nested dicts” in particular is not something I considered when thinking about ReadOnly[]before. -
I’d recommend adding a section to §“Specification” explaining how
get_type_hints()treatsReadOnly[], similar to the callouts in PEP 655. For completeness you might consider mentioning the altered behavior ofget_origin(), andget_args()as well.- I’d recommend that
get_type_hints()strip outReadOnly[]qualifiers by default unlessinclude_extras=True.
- I’d recommend that
-
Nit: Suggest adding the following changes in bold:
Suggested changes to the
typingmodule documentation, in line with current practice:
- Nit: In “Individual items can be excluded from mutate operations […]” the phrase “mutate operations” feels both overly technical and vague to me. Suggested wordsmithing to be less technical:
Individual items can be prevented from being changed by marking then as ReadOnly, allowing them only to be read.
-
Nit: For “pyright 1.1.332 fully implements this proposal.” suggest linking to the changelog or commit from pyright that indicates that it added ReadOnly support.
-
Nit: In the sentence “It would be reasonable for someone familiar with
frozen, […]” it’s not clear whatfrozenis referring to. There are no other uses of the word “frozen” in the PEP. Did you meanreadonlyinstead? -
There are multiple locations in this PEP that include a
Never-typed TypedDict item. (See example below.) It’s not clear to me what that even means. I suppose I don’t have specific feedback on this construction other than I find it confusing.
class B(TypedDict):
foo: NotRequired[Never]
-
In §“Rejected alternatives” maybe it would be worth talking about why the existing
Final[]qualifier couldn’t be used in place of introducing a newReadOnly[]qualifier? I think this was discussed before but I don’t remember what was said. -
(I did not review the formal rules in §“Type Consistency”, due to lack of energy/time)