Skip to content

Commit 89b45a3

Browse files
authored
Merge branch 'master' into strict-arg
2 parents 7fab9d9 + c821503 commit 89b45a3

File tree

7 files changed

+58
-25
lines changed

7 files changed

+58
-25
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Next release
44

5+
### Drop Support for Python 3.8
6+
7+
Mypy no longer supports running with Python 3.8, which has reached end-of-life.
8+
When running mypy with Python 3.9+, it is still possible to type check code
9+
that needs to support Python 3.8 with the `--python-version 3.8` argument.
10+
Support for this will be dropped in the first half of 2025!
11+
12+
Contributed by Marc Mueller (PR [17492](https://github.com/python/mypy/pull/17492)).
13+
14+
### Mypyc accelerated mypy wheels for aarch64
15+
16+
Mypy can compile itself to C extension modules using mypyc. This makes mypy 3-5x faster
17+
than if mypy is interpreted with pure Python. We now build and upload mypyc accelerated
18+
mypy wheels for `manylinux_aarch64` to PyPI, making it easy for users on such platforms
19+
to realise this speedup.
20+
21+
Contributed by Christian Bundy (PR [mypy_mypyc-wheels#76](https://github.com/mypyc/mypy_mypyc-wheels/pull/76))
22+
523
### `--strict-bytes`
624

725
By default, mypy treats an annotation of ``bytes`` as permitting ``bytearray`` and ``memoryview``.

mypy/plugin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ def fail(self, msg: str, ctx: Context, *, code: ErrorCode | None = None) -> None
170170
raise NotImplementedError
171171

172172
@abstractmethod
173-
def named_type(self, name: str, args: list[Type]) -> Instance:
173+
def named_type(self, fullname: str, args: list[Type], /) -> Instance:
174174
"""Construct an instance of a builtin type with given name."""
175175
raise NotImplementedError
176176

177177
@abstractmethod
178-
def analyze_type(self, typ: Type) -> Type:
178+
def analyze_type(self, typ: Type, /) -> Type:
179179
"""Analyze an unbound type using the default mypy logic."""
180180
raise NotImplementedError
181181

@@ -319,7 +319,8 @@ def fail(
319319
@abstractmethod
320320
def anal_type(
321321
self,
322-
t: Type,
322+
typ: Type,
323+
/,
323324
*,
324325
tvar_scope: TypeVarLikeScope | None = None,
325326
allow_tuple_literal: bool = False,
@@ -340,15 +341,15 @@ def class_type(self, self_type: Type) -> Type:
340341
raise NotImplementedError
341342

342343
@abstractmethod
343-
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
344+
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
344345
"""Lookup a symbol by its fully qualified name.
345346
346347
Raise an error if not found.
347348
"""
348349
raise NotImplementedError
349350

350351
@abstractmethod
351-
def lookup_fully_qualified_or_none(self, name: str) -> SymbolTableNode | None:
352+
def lookup_fully_qualified_or_none(self, fullname: str, /) -> SymbolTableNode | None:
352353
"""Lookup a symbol by its fully qualified name.
353354
354355
Return None if not found.
@@ -384,12 +385,12 @@ def add_plugin_dependency(self, trigger: str, target: str | None = None) -> None
384385
raise NotImplementedError
385386

386387
@abstractmethod
387-
def add_symbol_table_node(self, name: str, stnode: SymbolTableNode) -> Any:
388+
def add_symbol_table_node(self, name: str, symbol: SymbolTableNode) -> Any:
388389
"""Add node to global symbol table (or to nearest class if there is one)."""
389390
raise NotImplementedError
390391

391392
@abstractmethod
392-
def qualified_name(self, n: str) -> str:
393+
def qualified_name(self, name: str) -> str:
393394
"""Make qualified name using current module and enclosing class (if any)."""
394395
raise NotImplementedError
395396

mypy/semanal_shared.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ def lookup_qualified(
7676
raise NotImplementedError
7777

7878
@abstractmethod
79-
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
79+
def lookup_fully_qualified(self, fullname: str, /) -> SymbolTableNode:
8080
raise NotImplementedError
8181

8282
@abstractmethod
83-
def lookup_fully_qualified_or_none(self, name: str) -> SymbolTableNode | None:
83+
def lookup_fully_qualified_or_none(self, fullname: str, /) -> SymbolTableNode | None:
8484
raise NotImplementedError
8585

8686
@abstractmethod
@@ -176,7 +176,8 @@ def accept(self, node: Node) -> None:
176176
@abstractmethod
177177
def anal_type(
178178
self,
179-
t: Type,
179+
typ: Type,
180+
/,
180181
*,
181182
tvar_scope: TypeVarLikeScope | None = None,
182183
allow_tuple_literal: bool = False,
@@ -198,11 +199,11 @@ def basic_new_typeinfo(self, name: str, basetype_or_fallback: Instance, line: in
198199
raise NotImplementedError
199200

200201
@abstractmethod
201-
def schedule_patch(self, priority: int, fn: Callable[[], None]) -> None:
202+
def schedule_patch(self, priority: int, patch: Callable[[], None]) -> None:
202203
raise NotImplementedError
203204

204205
@abstractmethod
205-
def add_symbol_table_node(self, name: str, stnode: SymbolTableNode) -> bool:
206+
def add_symbol_table_node(self, name: str, symbol: SymbolTableNode) -> bool:
206207
"""Add node to the current symbol table."""
207208
raise NotImplementedError
208209

@@ -242,7 +243,7 @@ def parse_bool(self, expr: Expression) -> bool | None:
242243
raise NotImplementedError
243244

244245
@abstractmethod
245-
def qualified_name(self, n: str) -> str:
246+
def qualified_name(self, name: str) -> str:
246247
raise NotImplementedError
247248

248249
@property
@@ -309,7 +310,7 @@ def calculate_tuple_fallback(typ: TupleType) -> None:
309310

310311

311312
class _NamedTypeCallback(Protocol):
312-
def __call__(self, fully_qualified_name: str, args: list[Type] | None = None) -> Instance: ...
313+
def __call__(self, fullname: str, args: list[Type] | None = None) -> Instance: ...
313314

314315

315316
def paramspec_args(

mypy/subtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def visit_instance(self, left: Instance) -> bool:
499499
return True
500500
if type_state.is_cached_negative_subtype_check(self._subtype_kind, left, right):
501501
return False
502-
if not self.subtype_context.ignore_promotions:
502+
if not self.subtype_context.ignore_promotions and not right.type.is_protocol:
503503
for base in left.type.mro:
504504
if base._promote and any(
505505
self._is_subtype(p, self.right) for p in base._promote

mypy/typeanal.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ def lookup_qualified(
288288
) -> SymbolTableNode | None:
289289
return self.api.lookup_qualified(name, ctx, suppress_errors)
290290

291-
def lookup_fully_qualified(self, name: str) -> SymbolTableNode:
292-
return self.api.lookup_fully_qualified(name)
291+
def lookup_fully_qualified(self, fullname: str) -> SymbolTableNode:
292+
return self.api.lookup_fully_qualified(fullname)
293293

294294
def visit_unbound_type(self, t: UnboundType, defining_literal: bool = False) -> Type:
295295
typ = self.visit_unbound_type_nonoptional(t, defining_literal)
@@ -1762,8 +1762,8 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
17621762
self.fail(f"Parameter {idx} of Literal[...] is invalid", ctx, code=codes.VALID_TYPE)
17631763
return None
17641764

1765-
def analyze_type(self, t: Type) -> Type:
1766-
return t.accept(self)
1765+
def analyze_type(self, typ: Type) -> Type:
1766+
return typ.accept(self)
17671767

17681768
def fail(self, msg: str, ctx: Context, *, code: ErrorCode | None = None) -> None:
17691769
self.fail_func(msg, ctx, code=code)
@@ -1937,13 +1937,9 @@ def anal_var_defs(self, var_defs: Sequence[TypeVarLikeType]) -> list[TypeVarLike
19371937
return [self.anal_var_def(vd) for vd in var_defs]
19381938

19391939
def named_type(
1940-
self,
1941-
fully_qualified_name: str,
1942-
args: list[Type] | None = None,
1943-
line: int = -1,
1944-
column: int = -1,
1940+
self, fullname: str, args: list[Type] | None = None, line: int = -1, column: int = -1
19451941
) -> Instance:
1946-
node = self.lookup_fully_qualified(fully_qualified_name)
1942+
node = self.lookup_fully_qualified(fullname)
19471943
assert isinstance(node.node, TypeInfo)
19481944
any_type = AnyType(TypeOfAny.special_form)
19491945
if args is not None:

test-data/unit/check-type-promotion.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,19 @@ if isinstance(x, (float, complex)):
187187
else:
188188
reveal_type(x) # N: Revealed type is "builtins.int"
189189
[builtins fixtures/primitives.pyi]
190+
191+
[case testRejectPromotionsForProtocols]
192+
from typing import Protocol
193+
194+
class H(Protocol):
195+
def hex(self, /) -> str: ...
196+
197+
f: H = 1.0
198+
o: H = object() # E: Incompatible types in assignment (expression has type "object", variable has type "H")
199+
c: H = 1j # E: Incompatible types in assignment (expression has type "complex", variable has type "H")
200+
i: H = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "H")
201+
b: H = False # E: Incompatible types in assignment (expression has type "bool", variable has type "H")
202+
203+
class N(float): ...
204+
n: H = N()
205+
[builtins fixtures/primitives.pyi]

test-data/unit/fixtures/primitives.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class int:
2222
class float:
2323
def __float__(self) -> float: pass
2424
def __add__(self, x: float) -> float: pass
25+
def hex(self) -> str: pass
2526
class complex:
2627
def __add__(self, x: complex) -> complex: pass
2728
class bool(int): pass

0 commit comments

Comments
 (0)