Skip to content

Commit 984ddec

Browse files
Merge branch 'master' into dict-literals
2 parents 09e8aab + c5c12fa commit 984ddec

144 files changed

Lines changed: 3020 additions & 2029 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.

CHANGELOG.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ Support for this will be dropped in the first half of 2026!
1111

1212
Contributed by Marc Mueller (PR [20156](https://github.com/python/mypy/pull/20156)).
1313

14+
### Mypyc Accelerated Mypy Wheels for ARM Windows and Free Threading
15+
16+
For best performance, mypy can be compiled to C extension modules using mypyc. This makes
17+
mypy 3-5x faster than when interpreted with pure Python. We now build and upload mypyc
18+
accelerated mypy wheels for `win_arm64` and `cp314t-...` to PyPI, making it easy for Windows
19+
users on ARM and those using the free theading builds for Python 3.14 to realise this speedup
20+
-- just `pip install` the latest mypy.
21+
22+
Contributed by Marc Mueller
23+
(PR [mypy_mypyc-wheels#106](https://github.com/mypyc/mypy_mypyc-wheels/pull/106),
24+
PR [mypy_mypyc-wheels#110](https://github.com/mypyc/mypy_mypyc-wheels/pull/110)).
25+
26+
### Removed flags `--force-uppercase-builtins` and `--force-union-syntax`
27+
28+
The `--force-uppercase-builtins` flag was deprecated and has been a no-op since mypy 1.17.0.
29+
Since mypy has dropped support for Python 3.9, the `--force-union-syntax` flag is no longer
30+
necessary.
31+
32+
Contributed by Marc Mueller (PR [20410](https://github.com/python/mypy/pull/20410))
33+
and (PR [20405](https://github.com/python/mypy/pull/20405)).
34+
1435
## Mypy 1.19
1536

1637
We’ve just uploaded mypy 1.19.0 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
@@ -216,6 +237,17 @@ Related PRs:
216237

217238
Please see [git log](https://github.com/python/typeshed/commits/main?after=ebce8d766b41fbf4d83cf47c1297563a9508ff60+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
218239

240+
### Mypy 1.19.1
241+
242+
- Fix noncommutative joins with bounded TypeVars (Shantanu, PR [20345](https://github.com/python/mypy/pull/20345))
243+
- Respect output format for cached runs by serializing raw errors in cache metas (Ivan Levkivskyi, PR [20372](https://github.com/python/mypy/pull/20372))
244+
- Allow `types.NoneType` in match cases (A5rocks, PR [20383](https://github.com/python/mypy/pull/20383))
245+
- Fix mypyc generator regression with empty tuple (BobTheBuidler, PR [20371](https://github.com/python/mypy/pull/20371))
246+
- Fix crash involving Unpack-ed TypeVarTuple (Shantanu, PR [20323](https://github.com/python/mypy/pull/20323))
247+
- Fix crash on star import of redefinition (Ivan Levkivskyi, PR [20333](https://github.com/python/mypy/pull/20333))
248+
- Fix crash on typevar with forward ref used in other module (Ivan Levkivskyi, PR [20334](https://github.com/python/mypy/pull/20334))
249+
- Fail with an explicit error on PyPy (Ivan Levkivskyi, PR [20389](https://github.com/python/mypy/pull/20389))
250+
219251
### Acknowledgements
220252

221253
Thanks to all mypy contributors who contributed to this release:
@@ -251,7 +283,7 @@ Thanks to all mypy contributors who contributed to this release:
251283

252284
I’d also like to thank my employer, Dropbox, for supporting mypy development.
253285

254-
## Mypy 1.18.1
286+
## Mypy 1.18
255287

256288
We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
257289
Mypy is a static type checker for Python. This release includes new features, performance

docs/source/additional_features.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Type annotations can be added as follows:
135135

136136
.. code-block:: python
137137
138-
import attr
138+
import attrs
139139
140140
@attrs.define
141141
class A:

docs/source/command_line.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,6 @@ in error messages.
958958
useful or they may be overly noisy. If ``N`` is negative, there is
959959
no limit. The default limit is -1.
960960

961-
.. option:: --force-union-syntax
962-
963-
Always use ``Union[]`` and ``Optional[]`` for union types
964-
in error messages (instead of the ``|`` operator),
965-
even on Python 3.10+.
966-
967961

968962
.. _incremental:
969963

docs/source/config_file.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -930,15 +930,6 @@ These options may only be set in the global section (``[mypy]``).
930930

931931
Show absolute paths to files.
932932

933-
.. confval:: force_union_syntax
934-
935-
:type: boolean
936-
:default: False
937-
938-
Always use ``Union[]`` and ``Optional[]`` for union types
939-
in error messages (instead of the ``|`` operator),
940-
even on Python 3.10+.
941-
942933
Incremental mode
943934
****************
944935

mypy/checker.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5968,7 +5968,7 @@ def _make_fake_typeinfo_and_full_name(
59685968
errors.append((pretty_names_list, "would have incompatible method signatures"))
59695969
return None
59705970

5971-
curr_module.names[full_name] = SymbolTableNode(GDEF, info)
5971+
curr_module.names[full_name] = SymbolTableNode(GDEF, info, False, module_hidden=True)
59725972
return Instance(info, [], extra_attrs=instances[0].extra_attrs or instances[1].extra_attrs)
59735973

59745974
def intersect_instance_callable(self, typ: Instance, callable_type: CallableType) -> Instance:
@@ -6654,6 +6654,28 @@ def equality_type_narrowing_helper(
66546654
narrowable_operand_index_to_hash: dict[int, tuple[Key, ...]],
66556655
) -> tuple[TypeMap, TypeMap]:
66566656
"""Calculate type maps for '==', '!=', 'is' or 'is not' expression."""
6657+
# If we haven't been able to narrow types yet, we might be dealing with a
6658+
# explicit type(x) == some_type check
6659+
if_map, else_map = self.narrow_type_by_equality(
6660+
operator,
6661+
operands,
6662+
operand_types,
6663+
expr_indices,
6664+
narrowable_operand_index_to_hash.keys(),
6665+
)
6666+
if if_map == {} and else_map == {} and node is not None:
6667+
if_map, else_map = self.find_type_equals_check(node, expr_indices)
6668+
return if_map, else_map
6669+
6670+
def narrow_type_by_equality(
6671+
self,
6672+
operator: str,
6673+
operands: list[Expression],
6674+
operand_types: list[Type],
6675+
expr_indices: list[int],
6676+
narrowable_indices: AbstractSet[int],
6677+
) -> tuple[TypeMap, TypeMap]:
6678+
"""Calculate type maps for '==', '!=', 'is' or 'is not' expression, ignoring `type(x)` checks."""
66576679
# is_valid_target:
66586680
# Controls which types we're allowed to narrow exprs to. Note that
66596681
# we cannot use 'is_literal_type_like' in both cases since doing
@@ -6699,20 +6721,15 @@ def has_no_custom_eq_checks(t: Type) -> bool:
66996721
operands,
67006722
operand_types,
67016723
expr_indices,
6702-
narrowable_operand_index_to_hash.keys(),
6724+
narrowable_indices,
67036725
is_valid_target,
67046726
coerce_only_in_literal_context,
67056727
)
67066728

67076729
if if_map == {} and else_map == {}:
67086730
if_map, else_map = self.refine_away_none_in_comparison(
6709-
operands, operand_types, expr_indices, narrowable_operand_index_to_hash.keys()
6731+
operands, operand_types, expr_indices, narrowable_indices
67106732
)
6711-
6712-
# If we haven't been able to narrow types yet, we might be dealing with a
6713-
# explicit type(x) == some_type check
6714-
if if_map == {} and else_map == {}:
6715-
if_map, else_map = self.find_type_equals_check(node, expr_indices)
67166733
return if_map, else_map
67176734

67186735
def propagate_up_typemap_info(self, new_types: TypeMap) -> TypeMap:
@@ -6947,6 +6964,11 @@ def should_coerce_inner(typ: Type) -> bool:
69476964
for i in chain_indices:
69486965
expr_type = operand_types[i]
69496966
if should_coerce:
6967+
# TODO: doing this prevents narrowing a single-member Enum to literal
6968+
# of its member, because we expand it here and then refuse to add equal
6969+
# types to typemaps. As a result, `x: Foo; x == Foo.A` does not narrow
6970+
# `x` to `Literal[Foo.A]` iff `Foo` has exactly one member.
6971+
# See testMatchEnumSingleChoice
69506972
expr_type = coerce_to_literal(expr_type)
69516973
if not is_valid_target(get_proper_type(expr_type)):
69526974
continue

mypy/checker_shared.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from abc import abstractmethod
6-
from collections.abc import Iterator, Sequence
6+
from collections.abc import Iterator, Sequence, Set as AbstractSet
77
from contextlib import contextmanager
88
from typing import NamedTuple, overload
99

@@ -245,6 +245,17 @@ def conditional_types_with_intersection(
245245
) -> tuple[Type | None, Type | None]:
246246
raise NotImplementedError
247247

248+
@abstractmethod
249+
def narrow_type_by_equality(
250+
self,
251+
operator: str,
252+
operands: list[Expression],
253+
operand_types: list[Type],
254+
expr_indices: list[int],
255+
narrowable_indices: AbstractSet[int],
256+
) -> tuple[dict[Expression, Type] | None, dict[Expression, Type] | None]:
257+
raise NotImplementedError
258+
248259
@abstractmethod
249260
def check_deprecated(self, node: Node | None, context: Context) -> None:
250261
raise NotImplementedError

0 commit comments

Comments
 (0)