Skip to content

Commit 4b08554

Browse files
committed
Merge remote-tracking branch 'upstream/master' into checkmember-proto
2 parents 3a3cdf8 + c6c6e41 commit 4b08554

File tree

86 files changed

+2008
-309
lines changed

Some content is hidden

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

86 files changed

+2008
-309
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
echo debug build; python -c 'import sysconfig; print(bool(sysconfig.get_config_var("Py_DEBUG")))'
168168
echo os.cpu_count; python -c 'import os; print(os.cpu_count())'
169169
echo os.sched_getaffinity; python -c 'import os; print(len(getattr(os, "sched_getaffinity", lambda *args: [])(0)))'
170-
pip install tox==4.21.2
170+
pip install setuptools==75.1.0 tox==4.21.2
171171
172172
- name: Compiled with mypyc
173173
if: ${{ matrix.test_mypyc }}
@@ -230,7 +230,7 @@ jobs:
230230
default: 3.11.1
231231
command: python -c "import platform; print(f'{platform.architecture()=} {platform.machine()=}');"
232232
- name: Install tox
233-
run: pip install tox==4.21.2
233+
run: pip install setuptools==75.1.0 tox==4.21.2
234234
- name: Setup tox environment
235235
run: tox run -e py --notest
236236
- name: Test

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ repos:
1111
- id: black
1212
exclude: '^(test-data/)'
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.9.10
14+
rev: v0.11.4
1515
hooks:
1616
- id: ruff
1717
args: [--exit-non-zero-on-fix]
1818
- repo: https://github.com/python-jsonschema/check-jsonschema
19-
rev: 0.31.0
19+
rev: 0.32.1
2020
hooks:
2121
- id: check-github-workflows
2222
- id: check-github-actions
@@ -43,7 +43,7 @@ repos:
4343
# but the integration only works if shellcheck is installed
4444
- "github.com/wasilibs/go-shellcheck/cmd/[email protected]"
4545
- repo: https://github.com/woodruffw/zizmor-pre-commit
46-
rev: v1.0.1
46+
rev: v1.5.2
4747
hooks:
4848
- id: zizmor
4949
- repo: local

docs/source/command_line.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,19 @@ of the above sections.
749749

750750
.. option:: --strict
751751

752-
This flag mode enables all optional error checking flags. You can see the
753-
list of flags enabled by strict mode in the full :option:`mypy --help` output.
752+
This flag mode enables a defined subset of optional error-checking flags.
753+
This subset primarily includes checks for inadvertent type unsoundness (i.e
754+
strict will catch type errors as long as intentional methods like type ignore
755+
or casting were not used.)
756+
757+
Note: the :option:`--warn-unreachable` flag
758+
is not automatically enabled by the strict flag.
759+
760+
The strict flag does not take precedence over other strict-related flags.
761+
Directly specifying a flag of alternate behavior will override the
762+
behavior of strict, regardless of the order in which they are passed.
763+
You can see the list of flags enabled by strict mode in the full
764+
:option:`mypy --help` output.
754765

755766
Note: the exact list of flags enabled by running :option:`--strict` may change
756767
over time.

docs/source/runtime_troubles.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ version of Python considers legal code. This section describes these scenarios
88
and explains how to get your code running again. Generally speaking, we have
99
three tools at our disposal:
1010

11-
* Use of ``from __future__ import annotations`` (:pep:`563`)
12-
(this behaviour may eventually be made the default in a future Python version)
1311
* Use of string literal types or type comments
1412
* Use of ``typing.TYPE_CHECKING``
13+
* Use of ``from __future__ import annotations`` (:pep:`563`)
1514

1615
We provide a description of these before moving onto discussion of specific
1716
problems you may encounter.

mypy/argmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def map_actuals_to_formals(
7878
elif actual_kind.is_named():
7979
assert actual_names is not None, "Internal error: named kinds without names given"
8080
name = actual_names[ai]
81-
if name in formal_names:
81+
if name in formal_names and formal_kinds[formal_names.index(name)] != nodes.ARG_STAR:
8282
formal_to_actual[formal_names.index(name)].append(ai)
8383
elif nodes.ARG_STAR2 in formal_kinds:
8484
formal_to_actual[formal_kinds.index(nodes.ARG_STAR2)].append(ai)

mypy/checker.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
750750
defn.is_explicit_override
751751
and not found_method_base_classes
752752
and found_method_base_classes is not None
753+
# If the class has Any fallback, we can't be certain that a method
754+
# is really missing - it might come from unfollowed import.
755+
and not defn.info.fallback_to_any
753756
):
754757
self.msg.no_overridable_method(defn.name, defn)
755758
self.check_explicit_override_decorator(defn, found_method_base_classes, defn.impl)
@@ -5285,12 +5288,15 @@ def visit_decorator_inner(
52855288
# For overloaded functions/properties we already checked override for overload as a whole.
52865289
if allow_empty or skip_first_item:
52875290
return
5288-
if e.func.info and not e.func.is_dynamic() and not e.is_overload:
5291+
if e.func.info and not e.is_overload:
52895292
found_method_base_classes = self.check_method_override(e)
52905293
if (
52915294
e.func.is_explicit_override
52925295
and not found_method_base_classes
52935296
and found_method_base_classes is not None
5297+
# If the class has Any fallback, we can't be certain that a method
5298+
# is really missing - it might come from unfollowed import.
5299+
and not e.func.info.fallback_to_any
52945300
):
52955301
self.msg.no_overridable_method(e.func.name, e.func)
52965302
self.check_explicit_override_decorator(e.func, found_method_base_classes)

mypy/checkexpr.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4096,7 +4096,7 @@ def lookup_definer(typ: Instance, attr_name: str) -> str | None:
40964096
results = []
40974097
for name, method, obj, arg in variants:
40984098
with self.msg.filter_errors(save_filtered_errors=True) as local_errors:
4099-
result = self.check_method_call(op_name, obj, method, [arg], [ARG_POS], context)
4099+
result = self.check_method_call(name, obj, method, [arg], [ARG_POS], context)
41004100
if local_errors.has_new_errors():
41014101
errors.append(local_errors.filtered_errors())
41024102
results.append(result)
@@ -4696,8 +4696,8 @@ def visit_cast_expr(self, expr: CastExpr) -> Type:
46964696
options = self.chk.options
46974697
if (
46984698
options.warn_redundant_casts
4699-
and not isinstance(get_proper_type(target_type), AnyType)
4700-
and source_type == target_type
4699+
and not is_same_type(target_type, AnyType(TypeOfAny.special_form))
4700+
and is_same_type(source_type, target_type)
47014701
):
47024702
self.msg.redundant_cast(target_type, expr)
47034703
if options.disallow_any_unimported and has_any_from_unimported_type(target_type):
@@ -6297,7 +6297,13 @@ def narrow_type_from_binder(
62976297
known_type, restriction, prohibit_none_typevar_overlap=True
62986298
):
62996299
return None
6300-
return narrow_declared_type(known_type, restriction)
6300+
narrowed = narrow_declared_type(known_type, restriction)
6301+
if isinstance(get_proper_type(narrowed), UninhabitedType):
6302+
# If we hit this case, it means that we can't reliably mark the code as
6303+
# unreachable, but the resulting type can't be expressed in type system.
6304+
# Falling back to restriction is more intuitive in most cases.
6305+
return restriction
6306+
return narrowed
63016307
return known_type
63026308

63036309
def has_abstract_type_part(self, caller_type: ProperType, callee_type: ProperType) -> bool:

0 commit comments

Comments
 (0)