Skip to content

Commit 98a72e7

Browse files
committed
Address reviewer feedback.
1 parent 15adb5b commit 98a72e7

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

docs/spec/distributing.rst

+17-28
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,13 @@ Stub files are syntactically valid Python files in the earliest Python version
4545
that is not yet end-of-life. They use a ``.pyi`` suffix. The Python syntax used
4646
by stub files is independent from the Python versions supported by the
4747
implementation, and from the Python version the type checker runs under (if
48-
any). Therefore, stubs may use the latest syntax features available in
49-
the earliest supported version, even if the implementation supports older
50-
versions.
51-
52-
For example, Python 3.7 added the ``async`` keyword (see :pep:`492`). Stubs may
53-
use it to mark coroutines, even if the implementation still uses the
54-
``@coroutine`` decorator. On the other hand, the ``type`` soft keyword from
55-
:pep:`695`, introduced in Python 3.12, is not valid in stubs until Python 3.11
56-
reaches end-of-life in October 2027.
57-
58-
Stubs are treated as if ``from __future__ import annotations`` is enabled. In
59-
particular, forward references do not need to be quoted, and syntax from newer
60-
versions than otherwise supported may be used in annotation contexts. For
61-
example, the pipe union syntax (``X | Y``) introduced in Python 3.10 may be used
62-
in annotation contexts even before Python 3.9 reaches end-of-life.
48+
any).
49+
50+
Type checkers should treat stubs as if ``from __future__ import annotations`` is
51+
enabled. In particular, forward references do not need to be quoted, and syntax
52+
from newer versions than otherwise supported may be used in annotation contexts.
53+
For example, the pipe union syntax (``X | Y``) introduced in Python 3.10 may be
54+
used in annotation contexts even before Python 3.9 reaches end-of-life.
6355

6456
.. _stub-file-supported-constructs:
6557

@@ -73,10 +65,7 @@ Type checkers should fully support these constructs:
7365
(``type: ignore``) comments
7466
* Import statements, including the standard :ref:`import-conventions` and cyclic
7567
imports
76-
* Module-level type aliases (e.g., ``X: TypeAlias = int``,
77-
``Y: TypeAlias = dict[str, _V]``)
78-
* Regular aliases (e.g., ``function_alias = some_function``) at both the module-
79-
and class-level
68+
* Aliases, including type aliases, at both the module and class level
8069
* :ref:`Simple version and platform checks <version-and-platform-checks>`
8170

8271
The constructs in the following subsections may be supported in a more limited
@@ -92,6 +81,8 @@ support the following expressions:
9281
* The ellipsis literal, ``...``, which can stand in for any value
9382
* Any value that is a
9483
:ref:`legal parameter for typing.Literal <literal-legal-parameters>`
84+
* Floating point literals, such as `3.14`
85+
* Complex literals, such as `1 + 2j`
9586

9687
Module Level Attributes
9788
"""""""""""""""""""""""
@@ -104,8 +95,8 @@ assignments::
10495
x = 0 # type: int
10596
x = ... # type: int
10697

107-
A variable annotated as ``Final`` and assigned a literal value has the
108-
corresponding ``Literal`` type::
98+
The :ref:`Literal shortcut using Final <literal-final-interactions>` should be
99+
supported::
109100

110101
x: Final = 0 # type is Literal[0]
111102

@@ -127,7 +118,7 @@ are expected to understand only the following constructs in class bodies:
127118
* Instance attributes follow the same rules as module level attributes
128119
(see above).
129120
* Method definitions (see below) and properties.
130-
* Method aliases.
121+
* Aliases.
131122
* Inner class definitions.
132123

133124
Yes::
@@ -140,6 +131,7 @@ Yes::
140131
def read_only(self) -> int: ...
141132
def do_stuff(self, y: str) -> None: ...
142133
doStuff = do_stuff
134+
IntList: TypeAlias = list[int]
143135
class Inner: ...
144136

145137
Functions and Methods
@@ -164,6 +156,7 @@ in the ``typing`` module, plus these additional ones:
164156
* ``property`` (including ``.setter`` and ``.deleter``)
165157
* ``abc.abstractmethod``
166158
* ``dataclasses.dataclass``
159+
* ``warnings.deprecated``
167160
* functions decorated with ``@typing.dataclass_transform``
168161

169162
The Typeshed Project
@@ -410,9 +403,5 @@ The following import forms re-export symbols:
410403
* ``import X as X`` (a redundant module alias): re-exports ``X``.
411404
* ``from Y import X as X`` (a redundant symbol alias): re-exports ``X``.
412405
* ``from Y import *``: if ``Y`` defines a module-level ``__all__`` list,
413-
re-exports all names in ``__all__``; otherwise, re-exports all symbols in
414-
``Y`` that do not begin with an underscore.
415-
* ``from . import bar`` in an ``__init__`` module: re-exports ``bar`` if it does
416-
not begin with an underscore.
417-
* ``from .bar import Bar`` in an ``__init__`` module: re-exports ``Bar`` if it
418-
does not begin with an underscore.
406+
re-exports all names in ``__all__``; otherwise, re-exports all public symbols
407+
in ``Y``'s global scope.

docs/spec/literal.rst

+2
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ involving Literal bools. For example, we can combine ``Literal[True]``,
506506
else:
507507
scalar += "foo" # Type checks: type of 'scalar' is narrowed to 'str'
508508

509+
.. _literal-final-interactions:
510+
509511
Interactions with Final
510512
"""""""""""""""""""""""
511513

0 commit comments

Comments
 (0)