Skip to content

Commit cdbbbb5

Browse files
Merge branch 'master' into fix-enum-with-property-match-exhaustion
2 parents 50d0967 + a646f33 commit cdbbbb5

File tree

122 files changed

+2419
-704
lines changed

Some content is hidden

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

122 files changed

+2419
-704
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

CHANGELOG.md

Lines changed: 155 additions & 155 deletions
Large diffs are not rendered by default.

docs/requirements-docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sphinx>=5.1.0
22
furo>=2022.3.4
3+
myst-parser>=4.0.0

docs/source/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- This file includes mypy/CHANGELOG.md into mypy documentation -->
2+
```{include} ../../CHANGELOG.md
3+
```

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# Add any Sphinx extension module names here, as strings. They can be
3636
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3737
# ones.
38-
extensions = ["sphinx.ext.intersphinx", "docs.source.html_builder"]
38+
extensions = ["sphinx.ext.intersphinx", "docs.source.html_builder", "myst_parser"]
3939

4040
# Add any paths that contain templates here, relative to this directory.
4141
templates_path = ["_templates"]

docs/source/error_code_list.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,34 @@ types you expect.
11491149

11501150
See :ref:`overloading <function-overloading>` for more explanation.
11511151

1152+
1153+
.. _code-overload-cannot-match:
1154+
1155+
Check for overload signatures that cannot match [overload-cannot-match]
1156+
--------------------------------------------------------------------------
1157+
1158+
Warn if an ``@overload`` variant can never be matched, because an earlier
1159+
overload has a wider signature. For example, this can happen if the two
1160+
overloads accept the same parameters and each parameter on the first overload
1161+
has the same type or a wider type than the corresponding parameter on the second
1162+
overload.
1163+
1164+
Example:
1165+
1166+
.. code-block:: python
1167+
1168+
from typing import overload, Union
1169+
1170+
@overload
1171+
def process(response1: object, response2: object) -> object:
1172+
...
1173+
@overload
1174+
def process(response1: int, response2: int) -> int: # E: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader [overload-cannot-match]
1175+
...
1176+
1177+
def process(response1: object, response2: object) -> object:
1178+
return response1 + response2
1179+
11521180
.. _code-annotation-unchecked:
11531181

11541182
Notify about an annotation in an unchecked function [annotation-unchecked]

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Contents
103103
error_code_list2
104104
additional_features
105105
faq
106+
changelog
106107

107108
.. toctree::
108109
:hidden:

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/checker.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ def extract_callable_type(self, inner_type: Type | None, ctx: Context) -> Callab
683683
inner_type = get_proper_type(inner_type)
684684
outer_type: CallableType | None = None
685685
if inner_type is not None and not isinstance(inner_type, AnyType):
686+
if isinstance(inner_type, TypeVarLikeType):
687+
inner_type = get_proper_type(inner_type.upper_bound)
686688
if isinstance(inner_type, TypeType):
687689
if isinstance(inner_type.item, Instance):
688690
inner_type = expand_type_by_instance(
@@ -5649,7 +5651,16 @@ def _is_truthy_type(self, t: ProperType) -> bool:
56495651
)
56505652
)
56515653

5652-
def _check_for_truthy_type(self, t: Type, expr: Expression) -> None:
5654+
def check_for_truthy_type(self, t: Type, expr: Expression) -> None:
5655+
"""
5656+
Check if a type can have a truthy value.
5657+
5658+
Used in checks like::
5659+
5660+
if x: # <---
5661+
5662+
not x # <---
5663+
"""
56535664
if not state.strict_optional:
56545665
return # if everything can be None, all bets are off
56555666

@@ -6143,7 +6154,7 @@ def has_no_custom_eq_checks(t: Type) -> bool:
61436154
if in_boolean_context:
61446155
# We don't check `:=` values in expressions like `(a := A())`,
61456156
# because they produce two error messages.
6146-
self._check_for_truthy_type(original_vartype, node)
6157+
self.check_for_truthy_type(original_vartype, node)
61476158
vartype = try_expanding_sum_type_to_union(original_vartype, "builtins.bool")
61486159

61496160
if_type = true_only(vartype)

mypy/checkexpr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,6 +4256,7 @@ def visit_unary_expr(self, e: UnaryExpr) -> Type:
42564256
op = e.op
42574257
if op == "not":
42584258
result: Type = self.bool_type()
4259+
self.chk.check_for_truthy_type(operand_type, e.expr)
42594260
else:
42604261
method = operators.unary_op_methods[op]
42614262
result, method_type = self.check_method_call_by_name(method, operand_type, [], [], e)

0 commit comments

Comments
 (0)