Skip to content

Commit 12a1608

Browse files
Merge branch 'main' into callable_any_return
2 parents 1f0b9bb + 56cbde4 commit 12a1608

476 files changed

Lines changed: 7145 additions & 2505 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Y: Flake8 is only used to run flake8-pyi, everything else is in Ruff
33
select = Y
44
# Ignore rules normally excluded by default
5-
extend-ignore = Y090,Y091
5+
# Also ignore Y041 (redundant (complex |) float | int), see
6+
# https://github.com/python/typeshed/issues/16059
7+
extend-ignore = Y041,Y090,Y091
68
per-file-ignores =
79
# Generated protobuf files:
810
# Y021: Include docstrings

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ documentation. Whenever you find them disagreeing, model the type
320320
information after the actual implementation and file an issue on the
321321
project's tracker to fix their documentation.
322322

323+
### Deprecations (using the `@deprecated` decorator)
324+
325+
Generally deprecactions using the `@deprecated` decorator are added more
326+
liberally in typeshed than runtime deprecation warnings. Here are some
327+
guidelines that can be deviated from in special cases.
328+
329+
Use `@deprecated` if and only if
330+
331+
- a feature is deprecated at runtime (either using `@deprecated` or with a
332+
runtime warning); or
333+
- a feature is documented to be deprecated (e.g. in API documention,
334+
docstrings, or comments).
335+
336+
For standard library features that are not deprecated in all Python versions
337+
currently supported by typeshed use `@deprecated` for
338+
339+
- all versions starting with the "Deprecated since" version, plus
340+
- all versions for which an alternative is available.
341+
323342
### Docstrings
324343

325344
Typeshed stubs should not include duplicated docstrings from the source code.

pyrightconfig.stricter.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@
7373
"stubs/parsimonious/parsimonious/nodes.pyi",
7474
"stubs/peewee",
7575
"stubs/pexpect",
76-
"stubs/pika",
76+
"stubs/pika/pika/adapters/twisted_connection.pyi",
77+
"stubs/pika/pika/adapters/utils/connection_workflow.pyi",
78+
"stubs/pika/pika/callback.pyi",
79+
"stubs/pika/pika/channel.pyi",
7780
"stubs/pony",
7881
"stubs/protobuf",
7982
"stubs/psutil/psutil/__init__.pyi",
8083
"stubs/psycopg2",
8184
"stubs/punq",
8285
"stubs/pyasn1",
86+
"stubs/pycups",
8387
"stubs/Pygments",
8488
"stubs/PyMySQL",
8589
"stubs/pyogrio",

stdlib/@tests/test_cases/builtins/check_pow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# that passing 0 for the third argument will lead to an exception being raised
1616
# (see discussion in #8566)
1717
#
18-
# assert_type(pow(2, 4, 0), NoReturn)
18+
# assert_type(pow(2, 4, 0), Never)
1919

2020
assert_type(pow(2, 4), int)
2121
# pyright infers a literal type here, but mypy does not.

stdlib/@tests/test_cases/builtins/check_reversed.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ def __getitem__(self, item: int) -> _T:
3131

3232

3333
len_and_get_item: MyLenAndGetItem[int] = MyLenAndGetItem()
34-
assert_type(list(reversed(len_and_get_item)), "list[int]")
34+
assert_type(reversed(len_and_get_item), "reversed[int]")
35+
36+
37+
class UnTrue:
38+
def __reversed__(self) -> UnFalse:
39+
return UnFalse()
40+
41+
42+
class UnFalse:
43+
def __reversed__(self) -> UnTrue:
44+
return UnTrue()
45+
46+
47+
assert_type(reversed(UnTrue()), "UnFalse")
48+
assert_type(reversed(reversed(UnTrue())), "UnTrue")

stdlib/__main__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
def __getattr__(name: str): ... # incomplete module
1+
def __getattr__(name: str, /): ... # incomplete module

stdlib/_ctypes.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class _UnionType(_CTypeBaseType):
249249
# At runtime, various attributes are created on a Union subclass based
250250
# on its _fields_. This method doesn't exist, but represents those
251251
# dynamically created attributes.
252-
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
252+
def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ...
253253
if sys.version_info < (3, 13):
254254
# Inherited from CType_Type starting on 3.13
255255
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
@@ -263,8 +263,8 @@ class Union(_CData, metaclass=_UnionType):
263263
_align_: ClassVar[int]
264264

265265
def __init__(self, *args: Any, **kw: Any) -> None: ...
266-
def __getattr__(self, name: str) -> Any: ...
267-
def __setattr__(self, name: str, value: Any) -> None: ...
266+
def __getattr__(self, name: str, /) -> Any: ...
267+
def __setattr__(self, name: str, value: Any, /) -> None: ...
268268

269269
# This class is not exposed. It calls itself _ctypes.PyCStructType.
270270
@type_check_only
@@ -277,7 +277,7 @@ class _PyCStructType(_CTypeBaseType):
277277
# At runtime, various attributes are created on a Structure subclass based
278278
# on its _fields_. This method doesn't exist, but represents those
279279
# dynamically created attributes.
280-
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...
280+
def __getattr__(self, name: str, /) -> _CField[Any, Any, Any]: ...
281281
if sys.version_info < (3, 13):
282282
# Inherited from CType_Type starting on 3.13
283283
def __mul__(cls: type[_CT], other: int) -> type[Array[_CT]]: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues]
@@ -295,7 +295,7 @@ class Structure(_CData, metaclass=_PyCStructType):
295295
_layout_: ClassVar[Literal["ms", "gcc-sysv"]]
296296

297297
def __init__(self, *args: Any, **kw: Any) -> None: ...
298-
def __getattr__(self, name: str) -> Any: ...
298+
def __getattr__(self, name: str, /) -> Any: ...
299299
def __setattr__(self, name: str, value: Any) -> None: ...
300300

301301
# This class is not exposed. It calls itself _ctypes.PyCArrayType.

stdlib/_sitebuiltins.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import sys
22
from collections.abc import Iterable
3-
from typing import ClassVar, Literal, NoReturn
3+
from typing import ClassVar, Literal
4+
from typing_extensions import Never
45

56
class Quitter:
67
name: str
78
eof: str
89
def __init__(self, name: str, eof: str) -> None: ...
9-
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...
10+
def __call__(self, code: sys._ExitCode = None) -> Never: ...
1011

1112
class _Printer:
1213
MAXLINES: ClassVar[Literal[23]]

stdlib/_thread.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ from _typeshed import structseq
44
from collections.abc import Callable
55
from threading import Thread
66
from types import TracebackType
7-
from typing import Any, Final, NoReturn, final, overload
8-
from typing_extensions import TypeVarTuple, Unpack, deprecated, disjoint_base
7+
from typing import Any, Final, final, overload
8+
from typing_extensions import Never, TypeVarTuple, Unpack, deprecated, disjoint_base
99

1010
_Ts = TypeVarTuple("_Ts")
1111

@@ -82,9 +82,9 @@ def start_new(function: Callable[[Unpack[_Ts]], object], args: tuple[Unpack[_Ts]
8282
def start_new(function: Callable[..., object], args: tuple[Any, ...], kwargs: dict[str, Any], /) -> int: ... # undocumented
8383

8484
def interrupt_main(signum: signal.Signals = signal.SIGINT, /) -> None: ...
85-
def exit() -> NoReturn: ...
85+
def exit() -> Never: ...
8686
@deprecated("Obsolete synonym. Use `exit()` instead.")
87-
def exit_thread() -> NoReturn: ... # undocumented
87+
def exit_thread() -> Never: ... # undocumented
8888
def allocate_lock() -> LockType: ...
8989
@deprecated("Obsolete synonym. Use `allocate_lock()` instead.")
9090
def allocate() -> LockType: ... # undocumented

stdlib/_typeshed/__init__.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ Unused: TypeAlias = object # stable
5858
# for more information.
5959
MaybeNone: TypeAlias = Any # stable
6060

61+
# typeshed-internal type aliases to facilitate transition from
62+
# `float` to either `float | int` or `float` (and similar for `complex`).
63+
# When you encounter one of these type aliases, you are encouraged to
64+
# replace them with the correct type. Please don't use them outside typeshed.
65+
# See https://github.com/python/typeshed/issues/16059 for details.
66+
FloatInt: TypeAlias = float | int
67+
ComplexInt: TypeAlias = complex | float | int
68+
6169
# Used to mark arguments that default to a sentinel value. This prevents
6270
# stubtest from complaining about the default value not matching.
6371
#

0 commit comments

Comments
 (0)