@@ -337,46 +337,6 @@ No::
337
337
DAY_FLAG: int
338
338
NIGHT_FLAG: int
339
339
340
- Overloads
341
- ---------
342
-
343
- All variants of overloaded functions and methods must have an ``@overload ``
344
- decorator. Do not include the implementation's final non-`@overload `-decorated
345
- definition.
346
-
347
- Yes::
348
-
349
- @overload
350
- def foo(x: str) -> str: ...
351
- @overload
352
- def foo(x: float) -> int: ...
353
-
354
- No::
355
-
356
- @overload
357
- def foo(x: str) -> str: ...
358
- @overload
359
- def foo(x: float) -> int: ...
360
- def foo(x: str | float) -> Any: ...
361
-
362
- Decorators
363
- ----------
364
-
365
- Include only the decorators listed :ref: `here <stub-decorators >`, whose effects
366
- are understood by all of the major type checkers. The behavior of other
367
- decorators should instead be incorporated into the types. For example, for the
368
- following function::
369
-
370
- import contextlib
371
- @contextlib.contextmanager
372
- def f():
373
- yield 42
374
-
375
- the stub definition should be::
376
-
377
- from contextlib import AbstractContextManager
378
- def f() -> AbstractContextManager[int]: ...
379
-
380
340
Documentation or Implementation
381
341
-------------------------------
382
342
@@ -621,30 +581,3 @@ No::
621
581
from typing import NamedTuple, TypedDict
622
582
Point = NamedTuple("Point", [('x', float), ('y', float)])
623
583
Thing = TypedDict("Thing", {'stuff': str, 'index': int})
624
-
625
- Built-in Generics
626
- -----------------
627
-
628
- :pep: `585 ` built-in generics are supported and should be used instead
629
- of the corresponding types from ``typing ``::
630
-
631
- from collections import defaultdict
632
-
633
- def foo(t: type[MyClass]) -> list[int]: ...
634
- x: defaultdict[int]
635
-
636
- Using imports from ``collections.abc `` instead of ``typing `` is
637
- generally possible and recommended::
638
-
639
- from collections.abc import Iterable
640
-
641
- def foo(iter: Iterable[int]) -> None: ...
642
-
643
- Unions
644
- ------
645
-
646
- Declaring unions with the shorthand `| ` syntax is recommended and supported by
647
- all type checkers::
648
-
649
- def foo(x: int | str) -> int | None: ... # recommended
650
- def foo(x: Union[int, str]) -> Optional[int]: ... # ok
0 commit comments