Skip to content

Commit f2a0461

Browse files
authored
Merge branch 'master' into fix-list-concat-type-context
2 parents 32f7d64 + d17b99e commit f2a0461

154 files changed

Lines changed: 7110 additions & 943 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.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
hooks:
2727
- id: codespell
2828
args:
29-
- --ignore-words-list=HAX,Nam,ccompiler,ot,statics,whet,zar
29+
- --ignore-words-list=HAX,Nam,ccompiler,keep-alives,ot,statics,whet,zar
3030
exclude: ^(mypy/test/|mypy/typeshed/|mypyc/test-data/|test-data/).+$
3131
- repo: https://github.com/rhysd/actionlint
3232
rev: v1.7.7

CHANGELOG.md

Lines changed: 398 additions & 1 deletion
Large diffs are not rendered by default.

misc/typeshed_patches/0001-Revert-Remove-redundant-inheritances-from-Iterator.patch

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From d3dabcf7b7aaf0997b59f0a28bb41d17b6098f2c Mon Sep 17 00:00:00 2001
1+
From b5d1e4c76d8139e1a20f9178e8123f3ee39084d2 Mon Sep 17 00:00:00 2001
22
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
33
Date: Sat, 21 Dec 2024 22:36:38 +0100
44
Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
@@ -15,7 +15,7 @@ Subject: [PATCH] Revert Remove redundant inheritances from Iterator in
1515
7 files changed, 34 insertions(+), 34 deletions(-)
1616

1717
diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi
18-
index 23b690a9c..0ce93a435 100644
18+
index 242093e1e..92bb4e5f4 100644
1919
--- a/mypy/typeshed/stdlib/_asyncio.pyi
2020
+++ b/mypy/typeshed/stdlib/_asyncio.pyi
2121
@@ -1,6 +1,6 @@
@@ -36,10 +36,10 @@ index 23b690a9c..0ce93a435 100644
3636
@property
3737
def _exception(self) -> BaseException | None: ...
3838
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
39-
index 1808e28e2..9db6f4fc7 100644
39+
index e63b74214..9ea382dd6 100644
4040
--- a/mypy/typeshed/stdlib/builtins.pyi
4141
+++ b/mypy/typeshed/stdlib/builtins.pyi
42-
@@ -1369,7 +1369,7 @@ class frozenset(AbstractSet[_T_co]):
42+
@@ -1368,7 +1368,7 @@ class frozenset(AbstractSet[_T_co]):
4343
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4444

4545
@disjoint_base
@@ -48,7 +48,7 @@ index 1808e28e2..9db6f4fc7 100644
4848
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
4949
def __iter__(self) -> Self: ...
5050
def __next__(self) -> tuple[int, _T]: ...
51-
@@ -1635,7 +1635,7 @@ else:
51+
@@ -1634,7 +1634,7 @@ else:
5252
exit: _sitebuiltins.Quitter
5353

5454
@disjoint_base
@@ -57,7 +57,7 @@ index 1808e28e2..9db6f4fc7 100644
5757
@overload
5858
def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ...
5959
@overload
60-
@@ -1706,7 +1706,7 @@ license: _sitebuiltins._Printer
60+
@@ -1705,7 +1705,7 @@ license: _sitebuiltins._Printer
6161
def locals() -> dict[str, Any]: ...
6262

6363
@disjoint_base
@@ -66,7 +66,7 @@ index 1808e28e2..9db6f4fc7 100644
6666
# 3.14 adds `strict` argument.
6767
if sys.version_info >= (3, 14):
6868
@overload
69-
@@ -2022,7 +2022,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
69+
@@ -2021,7 +2021,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex
7070
quit: _sitebuiltins.Quitter
7171

7272
@disjoint_base
@@ -75,7 +75,7 @@ index 1808e28e2..9db6f4fc7 100644
7575
@overload
7676
def __new__(cls, sequence: Reversible[_T], /) -> Iterator[_T]: ... # type: ignore[misc]
7777
@overload
78-
@@ -2100,7 +2100,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
78+
@@ -2101,7 +2101,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ...
7979
def vars(object: Any = ..., /) -> dict[str, Any]: ...
8080

8181
@disjoint_base
@@ -131,10 +131,10 @@ index 37783254c..db9c228f5 100644
131131
@overload
132132
def __init__(
133133
diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi
134-
index d26a4e1da..9d1cd84da 100644
134+
index 60e79bc2e..fd7daf11e 100644
135135
--- a/mypy/typeshed/stdlib/itertools.pyi
136136
+++ b/mypy/typeshed/stdlib/itertools.pyi
137-
@@ -28,7 +28,7 @@ _Predicate: TypeAlias = Callable[[_T], object]
137+
@@ -28,7 +28,7 @@ _Predicate = Callable[[_T], object]
138138
# Technically count can take anything that implements a number protocol and has an add method
139139
# but we can't enforce the add method
140140
@disjoint_base
@@ -295,13 +295,13 @@ index d26a4e1da..9d1cd84da 100644
295295
@overload
296296
def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ...
297297
diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
298-
index b79f9e773..f276372d0 100644
298+
index 5642e50d0..203c5887c 100644
299299
--- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi
300300
+++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi
301301
@@ -1,4 +1,4 @@
302302
-from collections.abc import Callable, Iterable, Mapping
303303
+from collections.abc import Callable, Iterable, Iterator, Mapping
304-
from multiprocessing.context import DefaultContext, Process
304+
from multiprocessing.context import DefaultContext, Process as _Process
305305
from types import GenericAlias, TracebackType
306306
from typing import Any, Final, Generic, TypeVar
307307
@@ -32,7 +32,7 @@ class MapResult(ApplyResult[list[_T]]):
@@ -314,10 +314,10 @@ index b79f9e773..f276372d0 100644
314314
def __iter__(self) -> Self: ...
315315
def next(self, timeout: float | None = None) -> _T: ...
316316
diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
317-
index 7c033bdf4..7bf020558 100644
317+
index 80a02079d..d1065a509 100644
318318
--- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi
319319
+++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi
320-
@@ -426,7 +426,7 @@ class Connection:
320+
@@ -437,7 +437,7 @@ class Connection:
321321
) -> Literal[False]: ...
322322

323323
@disjoint_base
@@ -327,5 +327,5 @@ index 7c033bdf4..7bf020558 100644
327327
@property
328328
def connection(self) -> Connection: ...
329329
--
330-
2.54.0
330+
2.55.0
331331

misc/upload-pypi.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,7 @@ def is_whl_or_tar(name: str) -> bool:
3131

3232

3333
def item_ok_for_pypi(name: str) -> bool:
34-
if not is_whl_or_tar(name):
35-
return False
36-
37-
name = name.removesuffix(".tar.gz")
38-
name = name.removesuffix(".whl")
39-
40-
if name.endswith("wasm32"):
41-
return False
42-
43-
return True
34+
return is_whl_or_tar(name)
4435

4536

4637
def get_release_for_tag(tag: str) -> dict[str, Any]:

mypy-requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ typing_extensions>=4.14.0; python_version>='3.15'
55
mypy_extensions>=1.0.0
66
pathspec>=1.0.0
77
tomli>=1.1.0; python_version<'3.11'
8-
librt>=0.11.0; platform_python_implementation != 'PyPy'
9-
ast-serialize>=0.5.0,<1.0.0
8+
librt>=0.13.0; platform_python_implementation != 'PyPy'
9+
ast-serialize>=0.6.0,<1.0.0

mypy/build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,9 @@ def parse_all(self, states: list[State], post_parse: bool = True) -> None:
10301030

10311031
parallel_states = []
10321032
for state in states:
1033-
if not self.fscache.exists(state.xpath, real_only=True):
1033+
if not self.fscache.exists(state.xpath, real_only=True) or (
1034+
self.shadow_map and self.maybe_swap_for_shadow_path(state.xpath) != state.xpath
1035+
):
10341036
state.source = state.get_source()
10351037
if state.tree is not None:
10361038
# The file was already parsed.
@@ -4343,7 +4345,7 @@ def load_graph(
43434345
for dep in st.ancestors + dependencies + st.suppressed:
43444346
ignored = dep in st.suppressed_set and dep not in entry_points
43454347
if ignored and dep not in added:
4346-
manager.missing_modules[dep] = SuppressionReason.NOT_FOUND
4348+
manager.missing_modules.setdefault(dep, SuppressionReason.NOT_FOUND)
43474349
# TODO: for now we skip this in the daemon as a performance optimization.
43484350
# This however creates a correctness issue, see #7777 and State.is_fresh().
43494351
if not manager.use_fine_grained_cache() or manager.options.warn_unused_configs:

mypy/checker.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,8 @@ def check_func_def(
14871487
# TODO: check recursively for inner type variables
14881488
if (
14891489
arg_type.variance == COVARIANT
1490-
and defn.name not in ("__init__", "__new__", "__post_init__")
1490+
and defn.name
1491+
not in {"__init__", "__new__", "__post_init__", "__replace__"}
14911492
and not is_private(defn.name) # private methods are not inherited
14921493
and (i != 0 or not found_self)
14931494
):
@@ -1825,6 +1826,7 @@ def check_unbound_return_typevar(self, typ: CallableType) -> None:
18251826
"Consider using the upper bound "
18261827
f"{format_type(typ.ret_type.upper_bound, self.options)} instead",
18271828
context=typ.ret_type,
1829+
code=TYPE_VAR,
18281830
)
18291831

18301832
def check_default_params(self, item: FuncItem, body_is_trivial: bool | None = None) -> None:
@@ -3132,7 +3134,7 @@ class C(B, A[int]): ... # this is unsafe because...
31323134
x: A[int] = C()
31333135
x.foo # ...runtime type is (str) -> None, while static type is (int) -> None
31343136
"""
3135-
if name in ("__init__", "__new__", "__init_subclass__"):
3137+
if name in {"__init__", "__new__", "__init_subclass__", "__replace__"}:
31363138
# __init__ and friends can be incompatible -- it's a special case.
31373139
return
31383140
first = base1.names[name]
@@ -6857,9 +6859,13 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
68576859
for known_item in container_item_types:
68586860
# Match the should_coerce_literals logic from narrow_type_by_identity_equality
68596861
p_known_item = get_proper_type(known_item)
6860-
if is_literal_type_like(p_known_item) or (
6861-
isinstance(p_known_item, Instance) and p_known_item.type.is_enum
6862-
):
6862+
if (
6863+
is_literal_type_like(p_known_item)
6864+
or (
6865+
isinstance(p_known_item, Instance)
6866+
and p_known_item.type.is_enum
6867+
)
6868+
) and not has_custom_eq_checks(p_known_item):
68636869
known_item = coerce_to_literal(known_item)
68646870
if_map, else_map = self.narrow_type_by_identity_equality(
68656871
"==",
@@ -8128,7 +8134,20 @@ def iterable_item_type(self, it: ProperType, context: Context) -> Type:
81288134
return self.analyze_iterable_item_type_without_expression(it, context)[1]
81298135

81308136
def function_type(self, func: FuncBase) -> FunctionLike:
8131-
return function_type(func, self.named_type("builtins.function"))
8137+
typ = function_type(func, self.named_type("builtins.function"))
8138+
if (
8139+
isinstance(func, FuncItem)
8140+
and func.is_coroutine
8141+
and not func.is_async_generator
8142+
and func.type is None
8143+
and isinstance(typ, CallableType)
8144+
):
8145+
any_type = AnyType(TypeOfAny.special_form)
8146+
ret_type = self.named_generic_type(
8147+
"typing.Coroutine", [any_type, any_type, typ.ret_type]
8148+
)
8149+
return typ.copy_modified(ret_type=ret_type)
8150+
return typ
81328151

81338152
def push_type_map(self, type_map: TypeMap, *, from_assignment: bool = True) -> None:
81348153
if is_unreachable_map(type_map):
@@ -8874,6 +8893,7 @@ def builtin_item_type(tp: Type) -> Type | None:
88748893
"builtins.list",
88758894
"builtins.tuple",
88768895
"builtins.dict",
8896+
"builtins.frozendict",
88778897
"builtins.set",
88788898
"builtins.frozenset",
88798899
"_collections_abc.dict_keys",

mypy/checker_shared.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ArgKind,
1717
Context,
1818
Expression,
19+
FuncBase,
1920
FuncItem,
2021
LambdaExpr,
2122
MypyFile,
@@ -28,6 +29,7 @@
2829
from mypy.plugin import CheckerPluginInterface, Plugin
2930
from mypy.types import (
3031
CallableType,
32+
FunctionLike,
3133
Instance,
3234
LiteralValue,
3335
Overloaded,
@@ -149,6 +151,10 @@ def expr_checker(self) -> ExpressionCheckerSharedApi:
149151
def named_type(self, name: str) -> Instance:
150152
raise NotImplementedError
151153

154+
@abstractmethod
155+
def function_type(self, func: FuncBase) -> FunctionLike:
156+
raise NotImplementedError
157+
152158
@abstractmethod
153159
def lookup_typeinfo(self, fullname: str) -> TypeInfo:
154160
raise NotImplementedError

mypy/checkexpr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@
150150
false_only,
151151
fixup_partial_type,
152152
freeze_all_type_vars,
153-
function_type,
154153
get_all_type_vars,
155154
get_type_vars,
156155
is_literal_type_like,
@@ -415,7 +414,7 @@ def analyze_static_reference(
415414
if isinstance(node, (Var, Decorator, OverloadedFuncDef)):
416415
return node.type or AnyType(TypeOfAny.special_form)
417416
elif isinstance(node, FuncDef):
418-
return function_type(node, self.named_type("builtins.function"))
417+
return self.chk.function_type(node)
419418
elif isinstance(node, TypeInfo):
420419
# Reference to a type object.
421420
if node.typeddict_type:

mypy/checkmember.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
bind_self,
4848
erase_to_bound,
4949
freeze_all_type_vars,
50-
function_type,
5150
get_all_type_vars,
5251
make_simplified_union,
5352
supported_self_type,
@@ -360,7 +359,7 @@ def analyze_instance_member_access(
360359
if mx.is_lvalue and not mx.suppress_errors:
361360
mx.msg.cant_assign_to_method(mx.context)
362361
if not isinstance(method, OverloadedFuncDef):
363-
signature = function_type(method, mx.named_type("builtins.function"))
362+
signature = mx.chk.function_type(method)
364363
else:
365364
if method.type is None:
366365
# Overloads may be not ready if they are decorated. Handle this in same
@@ -1325,7 +1324,7 @@ def analyze_class_attribute_access(
13251324
return AnyType(TypeOfAny.from_error)
13261325
else:
13271326
assert isinstance(node.node, SYMBOL_FUNCBASE_TYPES)
1328-
typ = function_type(node.node, mx.named_type("builtins.function"))
1327+
typ = mx.chk.function_type(node.node)
13291328
# Note: if we are accessing class method on class object, the cls argument is bound.
13301329
# Annotated and/or explicit class methods go through other code paths above, for
13311330
# unannotated implicit class methods we do this here.
@@ -1490,7 +1489,7 @@ def analyze_decorator_or_funcbase_access(
14901489
"""
14911490
if isinstance(defn, Decorator):
14921491
return analyze_var(name, defn.var, itype, mx)
1493-
typ = function_type(defn, mx.chk.named_type("builtins.function"))
1492+
typ = mx.chk.function_type(defn)
14941493
if isinstance(defn, (FuncDef, OverloadedFuncDef)) and defn.is_trivial_self:
14951494
return bind_self_fast(typ, mx.self_type)
14961495
typ = check_self_arg(typ, mx.self_type, defn.is_class, mx.context, name, mx.msg)

0 commit comments

Comments
 (0)