Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/st-paramspec-missing-args
Browse files Browse the repository at this point in the history
  • Loading branch information
sterliakov authored Sep 12, 2024
2 parents 63f9438 + 0c10367 commit 786fb55
Show file tree
Hide file tree
Showing 81 changed files with 1,398 additions and 378 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
- name: Install tox
run: pip install tox==4.11.0
- name: Setup tox environment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 44bc98bd50e7170887f0740b53ed95a8eb04f00e Mon Sep 17 00:00:00 2001
From 58c6a6ab863c1c38e95ccafaf13792ed9c00e499 Mon Sep 17 00:00:00 2001
From: Shantanu <[email protected]>
Date: Sat, 29 Oct 2022 12:47:21 -0700
Subject: [PATCH] Revert sum literal integer change (#13961)
Expand All @@ -19,18 +19,18 @@ within mypy, I might pursue upstreaming this in typeshed.
1 file changed, 1 insertion(+), 1 deletion(-)

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

9 changes: 7 additions & 2 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def tuple_fallback(typ: TupleType) -> Instance:
else:
items.append(item)
return Instance(
info, [make_simplified_union(items)], extra_attrs=typ.partial_fallback.extra_attrs
info,
# Note: flattening recursive unions is dangerous, since it can fool recursive
# types optimization in subtypes.py and go into infinite recursion.
[make_simplified_union(items, handle_recursive=False)],
extra_attrs=typ.partial_fallback.extra_attrs,
)


Expand Down Expand Up @@ -440,6 +444,7 @@ def make_simplified_union(
*,
keep_erased: bool = False,
contract_literals: bool = True,
handle_recursive: bool = True,
) -> ProperType:
"""Build union type with redundant union items removed.
Expand All @@ -465,7 +470,7 @@ def make_simplified_union(
to_union().
"""
# Step 1: expand all nested unions
items = flatten_nested_unions(items)
items = flatten_nested_unions(items, handle_recursive=handle_recursive)

# Step 2: fast path for single item
if len(items) == 1:
Expand Down
10 changes: 8 additions & 2 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@ def extend_args_for_prefix_and_suffix(


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

flat_items: list[Type] = []
for t in typelist:
tp = get_proper_type(t) if handle_type_alias_type else t
if handle_type_alias_type:
if not handle_recursive and isinstance(t, TypeAliasType) and t.is_recursive:
tp: Type = t
else:
tp = get_proper_type(t)
else:
tp = t
if isinstance(tp, ProperType) and isinstance(tp, UnionType):
flat_items.extend(
flatten_nested_unions(tp.items, handle_type_alias_type=handle_type_alias_type)
Expand Down
Loading

0 comments on commit 786fb55

Please sign in to comment.