Skip to content

Commit d304a08

Browse files
committed
Apply review suggestions
1 parent 0a7bdc4 commit d304a08

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

peps/pep-0705.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ The ``movie_string`` function in the first motivating example can then be typed
140140
else:
141141
return f'{movie["name"]} ({movie["year"]})'
142142

143-
A mixture of read-only and non-read-only items is permitted, allowing the second motivating example to be correctly type-hinted::
143+
A mixture of read-only and non-read-only items is permitted, allowing the second motivating example to be correctly annotated::
144144

145145
class HasTimestamp(TypedDict):
146146
timestamp: float
@@ -183,7 +183,7 @@ The ``typing.ReadOnly`` type qualifier is used to indicate that an item declared
183183
name: str
184184
members: ReadOnly[list[str]]
185185

186-
blur: Band = {"name": "blur", members: []}
186+
blur: Band = {"name": "blur", "members": []}
187187
blur["name"] = "Blur" # OK: "name" is not read-only
188188
blur["members"] = ["Damon Albarn"] # Type check error: "members" is read-only
189189
blur["members"].append("Damon Albarn") # OK: list is mutable
@@ -226,7 +226,7 @@ Subclasses can redeclare read-only items as non-read-only, allowing them to be m
226226
name: str
227227
year: int
228228

229-
album: Album = { name: "Flood", year: 1990 }
229+
album: Album = { "name": "Flood", "year": 1990 }
230230
album["year"] = 1973
231231
album["name"] = "Dark Side Of The Moon" # OK: "name" is not read-only in Album
232232

@@ -235,7 +235,7 @@ If a read-only item is not redeclared, it remains read-only::
235235
class Album(NamedDict):
236236
year: int
237237

238-
album: Album = { name: "Flood", year: 1990 }
238+
album: Album = { "name": "Flood", "year": 1990 }
239239
album["name"] = "Dark Side Of The Moon" # Type check error: "name" is read-only in Album
240240

241241
Subclasses can narrow value types of read-only items::
@@ -282,7 +282,7 @@ A TypedDict type ``A`` is consistent with TypedDict ``B`` if ``A`` is structural
282282

283283
Discussion:
284284

285-
* All non-specified items in a TypedDict implicitly have value type ``ReadOnly[NotRequired[Any]]`` (or ``ReadOnly[NotRequired[Unknown]]`` in pyright).
285+
* All non-specified items in a TypedDict implicitly have value type ``ReadOnly[NotRequired[object]]``.
286286

287287
* Read-only items behave covariantly, as they cannot be mutated. This is similar to container types such as ``Sequence``, and different from non-read-only items, which behave invariantly. Example::
288288

@@ -298,7 +298,7 @@ Discussion:
298298
b: B = {"x": 1}
299299
f(b) # Accepted by type checker
300300

301-
* A TypedDict type ``A`` with no explicit key ``'x'`` is not consistent with a TypedDict type ``B`` with a non-required key ``'x'``, since at runtime the key ``'x'`` could be present and have an incompatible type (which may not be visible through ``A`` due to structural subtyping). The only exception to this rule is if the item in ``B`` is read-only, and the value type is a top type (``object``, ``Any`` or pylance's ``Unknown``). For example::
301+
* A TypedDict type ``A`` with no explicit key ``'x'`` is not consistent with a TypedDict type ``B`` with a non-required key ``'x'``, since at runtime the key ``'x'`` could be present and have an incompatible type (which may not be visible through ``A`` due to structural subtyping). The only exception to this rule is if the item in ``B`` is read-only, and the value type is of top type (``object``). For example::
302302

303303
class A(TypedDict):
304304
x: int
@@ -330,7 +330,7 @@ The merge operation (``d1 | d2``) creates a new dictionary with the merged keys
330330

331331
Type checkers should conform to the following rules, even if they are not expressed correctly in the typeshed due to language constraints.
332332

333-
If the merger of two TypedDict objects of type ``A`` and ``B`` are assigned to a TypedDict of type ``C``, the type checker should verify that:
333+
If the merger of two TypedDict objects of type ``A`` and ``B`` is assigned to a TypedDict of type ``C``, the type checker should verify that:
334334

335335
* for each key in ``C``, one of the following holds:
336336

@@ -405,7 +405,7 @@ If a shallow copy of TypedDict type ``A`` is assigned to TypedDict type ``B``, t
405405

406406
* for each key in ``B``, one of the following holds:
407407

408-
* the associated value type in of top type
408+
* the associated value type is of top type
409409
* the key is in ``A``, and the associated value type in ``A`` is consistent with the value type in ``B``
410410

411411
* if a key is required in ``B``, it is required in ``A``
@@ -414,7 +414,7 @@ If a deep copy of TypedDict type ``A`` is assigned to TypedDict type ``B``, the
414414

415415
* for each key in ``B``, one of the following holds:
416416

417-
* the associated value type in of top type
417+
* the associated value type is of top type
418418
* the key is in ``A``, and a deep copy of the associated value type in ``A`` could be assigned to the value type in ``B``
419419

420420
* if a key is required in ``B``, it is required in ``A``

0 commit comments

Comments
 (0)