Skip to content

Commit 11cf5d6

Browse files
authored
Minor changes to stub reference (#1166)
1 parent 8ecc93f commit 11cf5d6

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

docs/source/stubs.rst

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ see PEP 561 [#pep561]_ for more information. The
7777
includes stubs for Python's standard library and several third-party
7878
packages. The stubs for the standard library are usually distributed with type checkers and do not
7979
require separate installation. Stubs for third-party libraries are
80-
available on the `Python Package Index <https://pypi.org>`_. A stub package for
81-
a library called ``widget`` will be called ``types-widget``.
80+
available on the `Python Package Index <https://pypi.org>`_.
81+
By convention, a stub package for a library called ``widget`` would be named
82+
``types-widget``.
8283

8384
Supported Constructs
8485
====================
@@ -491,7 +492,7 @@ do not get interpreted by type checkers as enum members.
491492
Yes::
492493

493494
from enum import Enum
494-
495+
495496
class Color(Enum):
496497
RED: int
497498
BLUE: int
@@ -508,7 +509,7 @@ Yes::
508509
No::
509510

510511
from enum import Enum
511-
512+
512513
class Color(Enum):
513514
RED: int
514515
BLUE: int
@@ -1005,27 +1006,6 @@ with the current type system or using the correct type is unergonomic.
10051006

10061007
Use ``float`` instead of ``int | float``.
10071008
Use ``None`` instead of ``Literal[None]``.
1008-
For argument types,
1009-
use ``bytes`` instead of ``bytes | memoryview | bytearray``.
1010-
1011-
Use ``Text`` in stubs that support Python 2 when something accepts both
1012-
``str`` and ``unicode``. Avoid using ``Text`` in stubs or branches for
1013-
Python 3 only.
1014-
1015-
Yes::
1016-
1017-
if sys.version_info < (3,):
1018-
def foo(s: Text) -> None: ...
1019-
else:
1020-
def foo(s: str, *, i: int) -> None: ...
1021-
def bar(s: Text) -> None: ...
1022-
1023-
No::
1024-
1025-
if sys.version_info < (3,):
1026-
def foo(s: unicode) -> None: ...
1027-
else:
1028-
def foo(s: Text, *, i: int) -> None: ...
10291009

10301010
For arguments, prefer protocols and abstract types (``Mapping``,
10311011
``Sequence``, ``Iterable``, etc.). If an argument accepts literally any value,

0 commit comments

Comments
 (0)