Skip to content

Commit 690cf3c

Browse files
authored
Merge branch 'main' into removing-setuptools._distutils
2 parents ea6c488 + 6d0402c commit 690cf3c

File tree

29 files changed

+160
-101
lines changed

29 files changed

+160
-101
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
name: Run ruff on the test cases
2323
args:
2424
- "--exit-non-zero-on-fix"
25-
- "--select=FA,I,RUF100"
25+
- "--select=FA,I,ICN001,RUF100"
2626
- "--no-force-exclude"
2727
- "--unsafe-fixes"
2828
files: '.*test_cases/.+\.py$'

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ select = [
8383
"FURB169", # Compare the identities of `{object}` and None instead of their respective types
8484
"FURB177", # Prefer `Path.cwd()` over `Path().resolve()` for current-directory lookups
8585
"FURB187", # Use of assignment of `reversed` on list `{name}`
86+
# Used for lint.flake8-import-conventions.aliases
87+
"ICN001", # `{name}` should be imported as `{asname}`
8688
# Autofixable flake8-use-pathlib only
8789
"PTH201", # Do not pass the current directory explicitly to `Path`
8890
"PTH210", # Invalid suffix passed to `.with_suffix()`
@@ -217,6 +219,8 @@ ignore = [
217219
"PLC0414", # Import alias does not rename original package
218220
]
219221
"*_pb2.pyi" = [
222+
# Special autogenerated typing --> typing_extensions aliases
223+
"ICN001", # `{name}` should be imported as `{asname}`
220224
# Leave the docstrings as-is, matching source
221225
"D", # pydocstyle
222226
# See comment on black's force-exclude config above
@@ -226,6 +230,11 @@ ignore = [
226230
[tool.ruff.lint.pydocstyle]
227231
convention = "pep257" # https://docs.astral.sh/ruff/settings/#lint_pydocstyle_convention
228232

233+
[tool.ruff.lint.flake8-import-conventions.aliases]
234+
# Prevent aliasing these, as it causes false-negatives for certain rules
235+
typing_extensions = "typing_extensions"
236+
typing = "typing"
237+
229238
[tool.ruff.lint.isort]
230239
split-on-trailing-comma = false
231240
combine-as-imports = true

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,9 @@ typing_extensions\.Annotated # Undocumented implementation details
295295
# (Remove once 3.10.17 becomes available for all platforms)
296296
(email._header_value_parser.get_encoded_word)?
297297
(email._header_value_parser.make_quoted_pairs)?
298+
299+
# These methods have no default implementation for Python < 3.13.
300+
_pickle.Pickler.persistent_id
301+
_pickle.Unpickler.persistent_load
302+
pickle.Pickler.persistent_id
303+
pickle.Unpickler.persistent_load

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,9 @@ typing_extensions\.Annotated # Undocumented implementation details
259259
# (Remove once 3.11.12 becomes available for all platforms)
260260
(email._header_value_parser.get_encoded_word)?
261261
(email._header_value_parser.make_quoted_pairs)?
262+
263+
# These methods have no default implementation for Python < 3.13.
264+
_pickle.Pickler.persistent_id
265+
_pickle.Unpickler.persistent_load
266+
pickle.Pickler.persistent_id
267+
pickle.Unpickler.persistent_load

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,9 @@ sunau.Au_write.initfp
228228
threading.Lock # Factory function at runtime, but that wouldn't let us use it in type hints
229229
types.SimpleNamespace.__init__ # class doesn't accept positional arguments but has default C signature
230230
typing_extensions\.Annotated # Undocumented implementation details
231+
232+
# These methods have no default implementation for Python < 3.13.
233+
_pickle.Pickler.persistent_id
234+
_pickle.Unpickler.persistent_load
235+
pickle.Pickler.persistent_id
236+
pickle.Unpickler.persistent_load

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,9 @@ typing_extensions\.Annotated # Undocumented implementation details
245245
# Incompatible changes introduced in Python 3.9.22
246246
# (Remove once 3.9.22 becomes available for all platforms)
247247
(email._header_value_parser.get_encoded_word)?
248+
249+
# These methods have no default implementation for Python < 3.13.
250+
_pickle.Pickler.persistent_id
251+
_pickle.Unpickler.persistent_load
252+
pickle.Pickler.persistent_id
253+
pickle.Unpickler.persistent_load

stdlib/@tests/test_cases/check_re.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import mmap
44
import re
5-
import typing as t
5+
from typing import AnyStr, Match, Optional
66
from typing_extensions import assert_type
77

88

99
def check_search(str_pat: re.Pattern[str], bytes_pat: re.Pattern[bytes]) -> None:
10-
assert_type(str_pat.search("x"), t.Optional[t.Match[str]])
11-
assert_type(bytes_pat.search(b"x"), t.Optional[t.Match[bytes]])
12-
assert_type(bytes_pat.search(bytearray(b"x")), t.Optional[t.Match[bytes]])
13-
assert_type(bytes_pat.search(mmap.mmap(0, 10)), t.Optional[t.Match[bytes]])
10+
assert_type(str_pat.search("x"), Optional[Match[str]])
11+
assert_type(bytes_pat.search(b"x"), Optional[Match[bytes]])
12+
assert_type(bytes_pat.search(bytearray(b"x")), Optional[Match[bytes]])
13+
assert_type(bytes_pat.search(mmap.mmap(0, 10)), Optional[Match[bytes]])
1414

1515

16-
def check_search_with_AnyStr(pattern: re.Pattern[t.AnyStr], string: t.AnyStr) -> re.Match[t.AnyStr]:
16+
def check_search_with_AnyStr(pattern: re.Pattern[AnyStr], string: AnyStr) -> re.Match[AnyStr]:
1717
"""See issue #9591"""
1818
match = pattern.search(string)
1919
if match is None:

stdlib/@tests/test_cases/typing/check_regression_issue_9296.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from __future__ import annotations
22

3-
import typing as t
3+
from typing import Any, KeysView, TypeVar
44

5-
KT = t.TypeVar("KT")
5+
KT = TypeVar("KT")
66

77

8-
class MyKeysView(t.KeysView[KT]):
8+
class MyKeysView(KeysView[KT]):
99
pass
1010

1111

12-
d: dict[t.Any, t.Any] = {}
12+
d: dict[Any, Any] = {}
1313
dict_keys = type(d.keys())
1414

1515
# This should not cause an error like `Member "register" is unknown`:

stdlib/_pickle.pyi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from _typeshed import ReadableBuffer, SupportsWrite
32
from collections.abc import Callable, Iterable, Iterator, Mapping
43
from pickle import PickleBuffer as PickleBuffer
@@ -75,10 +74,9 @@ class Pickler:
7574
def memo(self, value: PicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
7675
def dump(self, obj: Any, /) -> None: ...
7776
def clear_memo(self) -> None: ...
78-
if sys.version_info >= (3, 13):
79-
def persistent_id(self, obj: Any, /) -> Any: ...
80-
else:
81-
persistent_id: Callable[[Any], Any]
77+
78+
# this method has no default implementation for Python < 3.13
79+
def persistent_id(self, obj: Any, /) -> Any: ...
8280

8381
@type_check_only
8482
class UnpicklerMemoProxy:
@@ -101,7 +99,6 @@ class Unpickler:
10199
def memo(self, value: UnpicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
102100
def load(self) -> Any: ...
103101
def find_class(self, module_name: str, global_name: str, /) -> Any: ...
104-
if sys.version_info >= (3, 13):
105-
def persistent_load(self, pid: Any, /) -> Any: ...
106-
else:
107-
persistent_load: Callable[[Any], Any]
102+
103+
# this method has no default implementation for Python < 3.13
104+
def persistent_load(self, pid: Any, /) -> Any: ...

stdlib/_typeshed/__init__.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# See the README.md file in this directory for more information.
44

55
import sys
6-
import typing_extensions
76
from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized
87
from dataclasses import Field
98
from os import PathLike
@@ -23,7 +22,7 @@ from typing import (
2322
final,
2423
overload,
2524
)
26-
from typing_extensions import Buffer, LiteralString, TypeAlias
25+
from typing_extensions import Buffer, LiteralString, Self as _Self, TypeAlias
2726

2827
_KT = TypeVar("_KT")
2928
_KT_co = TypeVar("_KT_co", covariant=True)
@@ -329,9 +328,9 @@ class structseq(Generic[_T_co]):
329328
# The second parameter will accept a dict of any kind without raising an exception,
330329
# but only has any meaning if you supply it a dict where the keys are strings.
331330
# https://github.com/python/typeshed/pull/6560#discussion_r767149830
332-
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> typing_extensions.Self: ...
331+
def __new__(cls, sequence: Iterable[_T_co], dict: dict[str, Any] = ...) -> _Self: ...
333332
if sys.version_info >= (3, 13):
334-
def __replace__(self, **kwargs: Any) -> typing_extensions.Self: ...
333+
def __replace__(self, **kwargs: Any) -> _Self: ...
335334

336335
# Superset of typing.AnyStr that also includes LiteralString
337336
AnyOrLiteralStr = TypeVar("AnyOrLiteralStr", str, bytes, LiteralString) # noqa: Y001

0 commit comments

Comments
 (0)