Skip to content

Commit 786fb55

Browse files
authored
Merge branch 'master' into bugfix/st-paramspec-missing-args
2 parents 63f9438 + 0c10367 commit 786fb55

Some content is hidden

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

81 files changed

+1398
-378
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- uses: actions/checkout@v4
3737
- uses: actions/setup-python@v5
3838
with:
39-
python-version: '3.8'
39+
python-version: '3.12'
4040
- name: Install tox
4141
run: pip install tox==4.11.0
4242
- name: Setup tox environment

misc/typeshed_patches/0001-Revert-sum-literal-integer-change-13961.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 44bc98bd50e7170887f0740b53ed95a8eb04f00e Mon Sep 17 00:00:00 2001
1+
From 58c6a6ab863c1c38e95ccafaf13792ed9c00e499 Mon Sep 17 00:00:00 2001
22
From: Shantanu <[email protected]>
33
Date: Sat, 29 Oct 2022 12:47:21 -0700
44
Subject: [PATCH] Revert sum literal integer change (#13961)
@@ -19,18 +19,18 @@ within mypy, I might pursue upstreaming this in typeshed.
1919
1 file changed, 1 insertion(+), 1 deletion(-)
2020

2121
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
22-
index 99919c64c..680cd5561 100644
22+
index ea9f8c894..a6065cc67 100644
2323
--- a/mypy/typeshed/stdlib/builtins.pyi
2424
+++ b/mypy/typeshed/stdlib/builtins.pyi
25-
@@ -1596,7 +1596,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
25+
@@ -1653,7 +1653,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
2626
# without creating many false-positive errors (see #7578).
2727
# Instead, we special-case the most common examples of this: bool and literal integers.
2828
@overload
29-
-def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... # type: ignore[overload-overlap]
30-
+def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... # type: ignore[overload-overlap]
29+
-def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
30+
+def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
3131
@overload
3232
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
3333
@overload
3434
--
35-
2.39.3 (Apple Git-146)
35+
2.46.0
3636

mypy/typeops.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ def tuple_fallback(typ: TupleType) -> Instance:
114114
else:
115115
items.append(item)
116116
return Instance(
117-
info, [make_simplified_union(items)], extra_attrs=typ.partial_fallback.extra_attrs
117+
info,
118+
# Note: flattening recursive unions is dangerous, since it can fool recursive
119+
# types optimization in subtypes.py and go into infinite recursion.
120+
[make_simplified_union(items, handle_recursive=False)],
121+
extra_attrs=typ.partial_fallback.extra_attrs,
118122
)
119123

120124

@@ -440,6 +444,7 @@ def make_simplified_union(
440444
*,
441445
keep_erased: bool = False,
442446
contract_literals: bool = True,
447+
handle_recursive: bool = True,
443448
) -> ProperType:
444449
"""Build union type with redundant union items removed.
445450
@@ -465,7 +470,7 @@ def make_simplified_union(
465470
to_union().
466471
"""
467472
# Step 1: expand all nested unions
468-
items = flatten_nested_unions(items)
473+
items = flatten_nested_unions(items, handle_recursive=handle_recursive)
469474

470475
# Step 2: fast path for single item
471476
if len(items) == 1:

mypy/types.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,7 +3629,7 @@ def extend_args_for_prefix_and_suffix(
36293629

36303630

36313631
def flatten_nested_unions(
3632-
types: Sequence[Type], handle_type_alias_type: bool = True
3632+
types: Sequence[Type], *, handle_type_alias_type: bool = True, handle_recursive: bool = True
36333633
) -> list[Type]:
36343634
"""Flatten nested unions in a type list."""
36353635
if not isinstance(types, list):
@@ -3643,7 +3643,13 @@ def flatten_nested_unions(
36433643

36443644
flat_items: list[Type] = []
36453645
for t in typelist:
3646-
tp = get_proper_type(t) if handle_type_alias_type else t
3646+
if handle_type_alias_type:
3647+
if not handle_recursive and isinstance(t, TypeAliasType) and t.is_recursive:
3648+
tp: Type = t
3649+
else:
3650+
tp = get_proper_type(t)
3651+
else:
3652+
tp = t
36473653
if isinstance(tp, ProperType) and isinstance(tp, UnionType):
36483654
flat_items.extend(
36493655
flatten_nested_unions(tp.items, handle_type_alias_type=handle_type_alias_type)

0 commit comments

Comments
 (0)