Skip to content

Commit d70a024

Browse files
Merge branch 'master' into star2arg-fastpath
2 parents 6b8b293 + 91487cb commit d70a024

Some content is hidden

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

75 files changed

+1749
-1124
lines changed

misc/typeshed_patches/0001-Remove-use-of-LiteralString-in-builtins-13743.patch

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From e6995c91231e1915eba43a29a22dd4cbfaf9e08e Mon Sep 17 00:00:00 2001
1+
From 805d7fc06a8bee350959512e0908a18a87b7f8c2 Mon Sep 17 00:00:00 2001
22
From: Shantanu <[email protected]>
33
Date: Mon, 26 Sep 2022 12:55:07 -0700
44
Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
@@ -8,7 +8,7 @@ Subject: [PATCH] Remove use of LiteralString in builtins (#13743)
88
1 file changed, 1 insertion(+), 99 deletions(-)
99

1010
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
11-
index 00728f42d..ea77a730f 100644
11+
index c7ab95482..3e93da36e 100644
1212
--- a/mypy/typeshed/stdlib/builtins.pyi
1313
+++ b/mypy/typeshed/stdlib/builtins.pyi
1414
@@ -63,7 +63,6 @@ from typing import ( # noqa: Y022,UP035
@@ -19,7 +19,7 @@ index 00728f42d..ea77a730f 100644
1919
ParamSpec,
2020
Self,
2121
TypeAlias,
22-
@@ -453,31 +452,16 @@ class str(Sequence[str]):
22+
@@ -468,31 +467,16 @@ class str(Sequence[str]):
2323
def __new__(cls, object: object = ...) -> Self: ...
2424
@overload
2525
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
@@ -51,7 +51,7 @@ index 00728f42d..ea77a730f 100644
5151
def format(self, *args: object, **kwargs: object) -> str: ...
5252
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
5353
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
54-
@@ -493,98 +477,34 @@ class str(Sequence[str]):
54+
@@ -508,98 +492,34 @@ class str(Sequence[str]):
5555
def isspace(self) -> bool: ...
5656
def istitle(self) -> bool: ...
5757
def isupper(self) -> bool: ...
@@ -150,7 +150,7 @@ index 00728f42d..ea77a730f 100644
150150
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
151151
@staticmethod
152152
@overload
153-
@@ -595,39 +515,21 @@ class str(Sequence[str]):
153+
@@ -610,39 +530,21 @@ class str(Sequence[str]):
154154
@staticmethod
155155
@overload
156156
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@@ -190,7 +190,7 @@ index 00728f42d..ea77a730f 100644
190190
- @overload
191191
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
192192
def __getnewargs__(self) -> tuple[str]: ...
193-
193+
def __format__(self, format_spec: str, /) -> str: ...
194194
--
195-
2.49.0
195+
2.50.1
196196

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5502,7 +5502,7 @@ def visit_with_stmt(self, s: WithStmt) -> None:
55025502
self.accept(s.body)
55035503

55045504
def check_untyped_after_decorator(self, typ: Type, func: FuncDef) -> None:
5505-
if not self.options.disallow_any_decorated or self.is_stub:
5505+
if not self.options.disallow_any_decorated or self.is_stub or self.current_node_deferred:
55065506
return
55075507

55085508
if mypy.checkexpr.has_any_type(typ):

mypy/semanal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ def remove_unpack_kwargs(self, defn: FuncDef, typ: CallableType) -> CallableType
10591059
# It is OK for TypedDict to have a key named 'kwargs'.
10601060
overlap.discard(typ.arg_names[-1])
10611061
if overlap:
1062-
overlapped = ", ".join([f'"{name}"' for name in overlap])
1062+
overlapped = ", ".join([f'"{name}"' for name in sorted(filter(None, overlap))])
10631063
self.fail(f"Overlap between argument names and ** TypedDict items: {overlapped}", defn)
10641064
new_arg_types = typ.arg_types[:-1] + [AnyType(TypeOfAny.from_error)]
10651065
return typ.copy_modified(arg_types=new_arg_types)
@@ -5332,13 +5332,15 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
53325332
s.expr.accept(self)
53335333

53345334
def visit_return_stmt(self, s: ReturnStmt) -> None:
5335+
old = self.statement
53355336
self.statement = s
53365337
if not self.is_func_scope():
53375338
self.fail('"return" outside function', s)
53385339
if self.return_stmt_inside_except_star_block:
53395340
self.fail('"return" not allowed in except* block', s, serious=True)
53405341
if s.expr:
53415342
s.expr.accept(self)
5343+
self.statement = old
53425344

53435345
def visit_raise_stmt(self, s: RaiseStmt) -> None:
53445346
self.statement = s

mypy/test/testsolve.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ def test_multiple_variables(self) -> None:
6464
)
6565

6666
def test_no_constraints_for_var(self) -> None:
67-
self.assert_solve([self.fx.t], [], [self.fx.uninhabited])
68-
self.assert_solve([self.fx.t, self.fx.s], [], [self.fx.uninhabited, self.fx.uninhabited])
67+
self.assert_solve([self.fx.t], [], [self.fx.a_uninhabited])
68+
self.assert_solve(
69+
[self.fx.t, self.fx.s], [], [self.fx.a_uninhabited, self.fx.a_uninhabited]
70+
)
6971
self.assert_solve(
7072
[self.fx.t, self.fx.s],
7173
[self.supc(self.fx.s, self.fx.a)],
72-
[self.fx.uninhabited, self.fx.a],
74+
[self.fx.a_uninhabited, self.fx.a],
7375
)
7476

7577
def test_simple_constraints_with_dynamic_type(self) -> None:
@@ -116,7 +118,7 @@ def test_poly_no_constraints(self) -> None:
116118
self.assert_solve(
117119
[self.fx.t, self.fx.u],
118120
[],
119-
[self.fx.uninhabited, self.fx.uninhabited],
121+
[self.fx.a_uninhabited, self.fx.a_uninhabited],
120122
allow_polymorphic=True,
121123
)
122124

@@ -152,7 +154,7 @@ def test_poly_free_pair_with_bounds_uninhabited(self) -> None:
152154
self.assert_solve(
153155
[self.fx.ub, self.fx.uc],
154156
[self.subc(self.fx.ub, self.fx.uc)],
155-
[self.fx.uninhabited, self.fx.uninhabited],
157+
[self.fx.a_uninhabited, self.fx.a_uninhabited],
156158
[],
157159
allow_polymorphic=True,
158160
)

mypy/test/typefixture.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def make_type_var(
7878
self.anyt = AnyType(TypeOfAny.special_form)
7979
self.nonet = NoneType()
8080
self.uninhabited = UninhabitedType()
81+
self.a_uninhabited = UninhabitedType()
82+
self.a_uninhabited.ambiguous = True
8183

8284
# Abstract class TypeInfos
8385

mypy/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,10 @@ def accept(self, visitor: TypeVisitor[T]) -> T:
12361236
return visitor.visit_uninhabited_type(self)
12371237

12381238
def __hash__(self) -> int:
1239-
return hash(UninhabitedType)
1239+
return hash((UninhabitedType, self.ambiguous))
12401240

12411241
def __eq__(self, other: object) -> bool:
1242-
return isinstance(other, UninhabitedType)
1242+
return isinstance(other, UninhabitedType) and other.ambiguous == self.ambiguous
12431243

12441244
def serialize(self) -> JsonDict:
12451245
return {".class": "UninhabitedType"}

mypy/typeshed/stdlib/_contextvars.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Token(Generic[_T]):
3939
if sys.version_info >= (3, 14):
4040
def __enter__(self) -> Self: ...
4141
def __exit__(
42-
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
42+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, /
4343
) -> None: ...
4444

4545
def copy_context() -> Context: ...

mypy/typeshed/stdlib/_frozen_importlib.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from _typeshed.importlib import LoaderProtocol
66
from collections.abc import Mapping, Sequence
77
from types import ModuleType
88
from typing import Any, ClassVar
9+
from typing_extensions import deprecated
910

1011
# Signature of `builtins.__import__` should be kept identical to `importlib.__import__`
1112
def __import__(
@@ -49,6 +50,7 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
4950
# MetaPathFinder
5051
if sys.version_info < (3, 12):
5152
@classmethod
53+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
5254
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
5355

5456
@classmethod
@@ -67,6 +69,10 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
6769
# Loader
6870
if sys.version_info < (3, 12):
6971
@staticmethod
72+
@deprecated(
73+
"Deprecated since Python 3.4; removed in Python 3.12. "
74+
"The module spec is now used by the import machinery to generate a module repr."
75+
)
7076
def module_repr(module: types.ModuleType) -> str: ...
7177
if sys.version_info >= (3, 10):
7278
@staticmethod
@@ -83,6 +89,7 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
8389
# MetaPathFinder
8490
if sys.version_info < (3, 12):
8591
@classmethod
92+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
8693
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
8794

8895
@classmethod
@@ -101,6 +108,10 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
101108
# Loader
102109
if sys.version_info < (3, 12):
103110
@staticmethod
111+
@deprecated(
112+
"Deprecated since Python 3.4; removed in Python 3.12. "
113+
"The module spec is now used by the import machinery to generate a module repr."
114+
)
104115
def module_repr(m: types.ModuleType) -> str: ...
105116
if sys.version_info >= (3, 10):
106117
@staticmethod

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def spec_from_file_location(
4343
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
4444
if sys.version_info < (3, 12):
4545
@classmethod
46+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
4647
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
4748

4849
@classmethod
@@ -70,6 +71,7 @@ class PathFinder(importlib.abc.MetaPathFinder):
7071
) -> ModuleSpec | None: ...
7172
if sys.version_info < (3, 12):
7273
@classmethod
74+
@deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.")
7375
def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ...
7476

7577
SOURCE_SUFFIXES: list[str]
@@ -158,7 +160,10 @@ if sys.version_info >= (3, 11):
158160
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
159161
if sys.version_info < (3, 12):
160162
@staticmethod
161-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
163+
@deprecated(
164+
"Deprecated since Python 3.4; removed in Python 3.12. "
165+
"The module spec is now used by the import machinery to generate a module repr."
166+
)
162167
def module_repr(module: types.ModuleType) -> str: ...
163168

164169
_NamespaceLoader = NamespaceLoader
@@ -176,12 +181,18 @@ else:
176181
def load_module(self, fullname: str) -> types.ModuleType: ...
177182
if sys.version_info >= (3, 10):
178183
@staticmethod
179-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
184+
@deprecated(
185+
"Deprecated since Python 3.4; removed in Python 3.12. "
186+
"The module spec is now used by the import machinery to generate a module repr."
187+
)
180188
def module_repr(module: types.ModuleType) -> str: ...
181189
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
182190
else:
183191
@classmethod
184-
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
192+
@deprecated(
193+
"Deprecated since Python 3.4; removed in Python 3.12. "
194+
"The module spec is now used by the import machinery to generate a module repr."
195+
)
185196
def module_repr(cls, module: types.ModuleType) -> str: ...
186197

187198
if sys.version_info >= (3, 13):

mypy/typeshed/stdlib/_interpchannels.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ class ChannelID:
1717
def send(self) -> Self: ...
1818
@property
1919
def recv(self) -> Self: ...
20-
def __eq__(self, other: object) -> bool: ...
21-
def __ge__(self, other: ChannelID) -> bool: ...
22-
def __gt__(self, other: ChannelID) -> bool: ...
20+
def __eq__(self, other: object, /) -> bool: ...
21+
def __ge__(self, other: ChannelID, /) -> bool: ...
22+
def __gt__(self, other: ChannelID, /) -> bool: ...
2323
def __hash__(self) -> int: ...
2424
def __index__(self) -> int: ...
2525
def __int__(self) -> int: ...
26-
def __le__(self, other: ChannelID) -> bool: ...
27-
def __lt__(self, other: ChannelID) -> bool: ...
28-
def __ne__(self, other: object) -> bool: ...
26+
def __le__(self, other: ChannelID, /) -> bool: ...
27+
def __lt__(self, other: ChannelID, /) -> bool: ...
28+
def __ne__(self, other: object, /) -> bool: ...
2929

3030
@final
3131
class ChannelInfo(structseq[int], tuple[bool, bool, bool, int, int, int, int, int]):

0 commit comments

Comments
 (0)