Skip to content

Commit 1513503

Browse files
authored
PEP 728: Fix formatting and code highlighting issues (#3659)
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 54ba2b4 commit 1513503

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

peps/pep-0728.rst

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Python-Version: 3.13
1212
Post-History: `09-Feb-2024 <https://discuss.python.org/t/pep-728-typeddict-with-typed-extra-items/45443>`__,
1313

1414

15-
.. highlight:: rst
16-
1715
Abstract
1816
========
1917

@@ -286,17 +284,17 @@ added in a subclass, all of the following conditions should apply:
286284

287285
- If ``__extra__`` is read-only
288286

289-
- The item can be either required or non-required
287+
- The item can be either required or non-required
290288

291-
- The item's value type is consistent with ``T``
289+
- The item's value type is consistent with ``T``
292290

293291
- If ``__extra__`` is not read-only
294292

295-
- The item is non-required
293+
- The item is non-required
296294

297-
- The item's value type is consistent with ``T``
295+
- The item's value type is consistent with ``T``
298296

299-
- ``T`` is consistent with the item's value type
297+
- ``T`` is consistent with the item's value type
300298

301299
- If ``__extra__`` is not redeclared, the subclass inherits it as-is.
302300

@@ -337,19 +335,19 @@ infinite set of items that all satisfy the following conditions:
337335

338336
- If ``__extra__`` is read-only
339337

340-
- The key's value type is consistent with ``T``
338+
- The key's value type is consistent with ``T``
341339

342-
- The key is not in ``S``.
340+
- The key is not in ``S``.
343341

344342
- If ``__extra__`` is not read-only
345343

346-
- The key is non-required
344+
- The key is non-required
347345

348-
- The key's value type is consistent with ``T``
346+
- The key's value type is consistent with ``T``
349347

350-
- ``T`` is consistent with the key's value type
348+
- ``T`` is consistent with the key's value type
351349

352-
- The key is not in ``S``.
350+
- The key is not in ``S``.
353351

354352
For type checking purposes, let ``__extra__`` be a non-required pseudo-item to
355353
be included whenever "for each ... item/key" is stated in
@@ -362,25 +360,25 @@ and we modify it as follows:
362360

363361
* For each item in ``B``, ``A`` has the corresponding key, unless the item
364362
in ``B`` is read-only, not required, and of top value type
365-
(``ReadOnly[NotRequired[object]]``). [Edit: Otherwise, if the
363+
(``ReadOnly[NotRequired[object]]``). **[Edit: Otherwise, if the
366364
corresponding key with the same name cannot be found in ``A``, "__extra__"
367-
is considered the corresponding key.]
365+
is considered the corresponding key.]**
368366

369-
* For each item in ``B``, if ``A`` has the corresponding key [Edit: or
370-
"__extra__"], the corresponding value type in ``A`` is consistent with the
367+
* For each item in ``B``, if ``A`` has the corresponding key **[Edit: or
368+
"__extra__"]**, the corresponding value type in ``A`` is consistent with the
371369
value type in ``B``.
372370

373371
* For each non-read-only item in ``B``, its value type is consistent with
374-
the corresponding value type in ``A``. [Edit: if the corresponding key
372+
the corresponding value type in ``A``. **[Edit: if the corresponding key
375373
with the same name cannot be found in ``A``, "__extra__" is considered the
376-
corresponding key.]
374+
corresponding key.]**
377375

378376
* For each required key in ``B``, the corresponding key is required in ``A``.
379377
For each non-required key in ``B``, if the item is not read-only in ``B``,
380378
the corresponding key is not required in ``A``.
381-
[Edit: if the corresponding key with the same name cannot be found in
379+
**[Edit: if the corresponding key with the same name cannot be found in
382380
``A``, "__extra__" is considered to be non-required as the corresponding
383-
key.]
381+
key.]**
384382

385383
The following examples illustrate these checks in action.
386384

@@ -412,7 +410,7 @@ corresponding key. ``"year"`` being required violates the rule "For each
412410
required key in ``B``, the corresponding key is required in ``A``".
413411

414412
When ``__extra__`` is defined to be read-only in a TypedDict type, it is possible
415-
for an item to have a narrower type than ``__extra__``'s value type.
413+
for an item to have a narrower type than ``__extra__``'s value type::
416414

417415
class Movie(TypedDict):
418416
name: str
@@ -450,7 +448,7 @@ Interaction with Mapping[KT, VT]
450448
A TypedDict type can be consistent with ``Mapping[KT, VT]`` types other than
451449
``Mapping[str, object]`` as long as the union of value types on the TypedDict
452450
type is consistent with ``VT``. It is an extension of this rule from the typing
453-
spec::
451+
spec:
454452

455453
* A TypedDict with all ``int`` values is not consistent with
456454
``Mapping[str, int]``, since there may be additional non-``int``
@@ -509,7 +507,7 @@ For example::
509507
regular_dict: dict[str, int] = not_required_num # OK
510508
f(not_required_num) # OK
511509

512-
In this case, methods that are previously unavailable on a TypedDict are allowed.
510+
In this case, methods that are previously unavailable on a TypedDict are allowed::
513511

514512
not_required_num.clear() # OK
515513

@@ -631,7 +629,7 @@ Acknowledgments
631629

632630
Thanks to Jelle Zijlstra for sponsoring this PEP and providing review feedback,
633631
Eric Traut who `proposed the original design
634-
<https://mail.python.org/archives/list/[email protected]/message/3Z72OQWVTOVS6UYUUCCII2UZN56PV5II/>`
632+
<https://mail.python.org/archives/list/[email protected]/message/3Z72OQWVTOVS6UYUUCCII2UZN56PV5II/>`__
635633
this PEP iterates on, and Alice Purcell for offering their perspective as the
636634
author of :pep:`705`.
637635

0 commit comments

Comments
 (0)