Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita329153

Browse files
authored
bpo-37759: Add examples for the new typing features (GH-16763)
1 parent61a6db5 commita329153

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

‎Doc/whatsnew/3.8.rst‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,17 +1048,33 @@ typing
10481048

10491049
The:mod:`typing` module incorporates several new features:
10501050

1051-
* Protocol definitions. See:pep:`544`,:class:`typing.Protocol` and
1052-
:func:`typing.runtime_checkable`. Simple ABCs like
1053-
:class:`typing.SupportsInt` are now ``Protocol`` subclasses.
1054-
10551051
* A dictionary type with per-key types. See:pep:`589` and
10561052
:class:`typing.TypedDict`.
1053+
TypedDict uses only string keys. By default, every key is required
1054+
to be present. Specify "total=False" to allow keys to be optional::
1055+
1056+
class Location(TypedDict, total=False):
1057+
lat_long: tuple
1058+
grid_square: str
1059+
xy_coordinate: tuple
10571060

10581061
* Literal types. See:pep:`586` and:class:`typing.Literal`.
1062+
Literal types indicate that a parameter or return value
1063+
is constrained to one or more specific literal values::
1064+
1065+
def get_status(port: int) -> Literal['connected', 'disconnected']:
1066+
...
10591067

10601068
* "Final" variables, functions, methods and classes. See:pep:`591`,
10611069
:class:`typing.Final` and:func:`typing.final`.
1070+
The final qualifier instructs a static type checker to restrict
1071+
subclassing, overriding, or reassignment::
1072+
1073+
pi: Final[float] = 3.1415926536
1074+
1075+
* Protocol definitions. See:pep:`544`,:class:`typing.Protocol` and
1076+
:func:`typing.runtime_checkable`. Simple ABCs like
1077+
:class:`typing.SupportsInt` are now ``Protocol`` subclasses.
10621078

10631079
* New protocol class:class:`typing.SupportsIndex`.
10641080

@@ -1527,7 +1543,7 @@ Changes in Python behavior
15271543
terminate the current thread if called while the interpreter is
15281544
finalizing, making them consistent with:c:func:`PyEval_RestoreThread`,
15291545
:c:func:`Py_END_ALLOW_THREADS`, and:c:func:`PyGILState_Ensure`. If this
1530-
behaviour is not desired, guard the call by checking:c:func:`_Py_IsFinalizing`
1546+
behavior is not desired, guard the call by checking:c:func:`_Py_IsFinalizing`
15311547
or:c:func:`sys.is_finalizing`.
15321548

15331549
Changes in the Python API

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp