Skip to content

Commit e202c7a

Browse files
committed
Merge branch 'master' into fix/fix_narrow_promotions_in_unions
2 parents 2c820d3 + 2ba79cb commit e202c7a

Some content is hidden

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

48 files changed

+829
-465
lines changed

docs/source/error_code_list2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ Example:
616616
617617
.. _code-exhaustive-match:
618618

619-
Check that match statements match exhaustively [match-exhaustive]
619+
Check that match statements match exhaustively [exhaustive-match]
620620
-----------------------------------------------------------------------
621621

622622
If enabled with :option:`--enable-error-code exhaustive-match <mypy --enable-error-code>`,

misc/self_compile_info.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Print list of files compiled when compiling self (mypy and mypyc)."""
2+
3+
import argparse
4+
import sys
5+
from typing import Any
6+
7+
import setuptools
8+
9+
import mypyc.build
10+
11+
12+
class FakeExtension:
13+
def __init__(self, *args: Any, **kwargs: Any) -> None:
14+
pass
15+
16+
17+
def fake_mypycify(args: list[str], **kwargs: Any) -> list[FakeExtension]:
18+
for target in sorted(args):
19+
if not target.startswith("-"):
20+
print(target)
21+
return [FakeExtension()]
22+
23+
24+
def fake_setup(*args: Any, **kwargs: Any) -> Any:
25+
pass
26+
27+
28+
def main() -> None:
29+
parser = argparse.ArgumentParser(
30+
description="Print list of files compiled when compiling self. Run in repository root."
31+
)
32+
parser.parse_args()
33+
34+
# Prepare fake state for running setup.py.
35+
mypyc.build.mypycify = fake_mypycify # type: ignore[assignment]
36+
setuptools.Extension = FakeExtension # type: ignore[misc, assignment]
37+
setuptools.setup = fake_setup
38+
sys.argv = [sys.argv[0], "--use-mypyc"]
39+
40+
# Run setup.py at the root of the repository.
41+
import setup # noqa: F401
42+
43+
44+
if __name__ == "__main__":
45+
main()

mypy/checker.py

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mypy.constraints import SUPERTYPE_OF
2626
from mypy.erasetype import erase_type, erase_typevars, remove_instance_last_known_values
2727
from mypy.errorcodes import TYPE_VAR, UNUSED_AWAITABLE, UNUSED_COROUTINE, ErrorCode
28-
from mypy.errors import Errors, ErrorWatcher, LoopErrorWatcher, report_internal_error
28+
from mypy.errors import ErrorInfo, Errors, ErrorWatcher, LoopErrorWatcher, report_internal_error
2929
from mypy.expandtype import expand_type
3030
from mypy.literals import Key, extract_var_from_literal_hash, literal, literal_hash
3131
from mypy.maptype import map_instance_to_supertype
@@ -117,7 +117,6 @@
117117
TypeAlias,
118118
TypeAliasStmt,
119119
TypeInfo,
120-
TypeVarExpr,
121120
UnaryExpr,
122121
Var,
123122
WhileStmt,
@@ -697,11 +696,9 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
697696
assert isinstance(defn.items[0], Decorator)
698697
self.visit_decorator(defn.items[0])
699698
if defn.items[0].var.is_settable_property:
700-
# TODO: here and elsewhere we assume setter immediately follows getter.
701-
assert isinstance(defn.items[1], Decorator)
702699
# Perform a reduced visit just to infer the actual setter type.
703-
self.visit_decorator_inner(defn.items[1], skip_first_item=True)
704-
setter_type = defn.items[1].var.type
700+
self.visit_decorator_inner(defn.setter, skip_first_item=True)
701+
setter_type = defn.setter.var.type
705702
# Check if the setter can accept two positional arguments.
706703
any_type = AnyType(TypeOfAny.special_form)
707704
fallback_setter_type = CallableType(
@@ -712,7 +709,7 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
712709
fallback=self.named_type("builtins.function"),
713710
)
714711
if setter_type and not is_subtype(setter_type, fallback_setter_type):
715-
self.fail("Invalid property setter signature", defn.items[1].func)
712+
self.fail("Invalid property setter signature", defn.setter.func)
716713
setter_type = self.extract_callable_type(setter_type, defn)
717714
if not isinstance(setter_type, CallableType) or len(setter_type.arg_types) != 2:
718715
# TODO: keep precise type for callables with tricky but valid signatures.
@@ -2171,7 +2168,7 @@ def check_setter_type_override(self, defn: OverloadedFuncDef, base: TypeInfo) ->
21712168
assert typ is not None and original_type is not None
21722169

21732170
if not is_subtype(original_type, typ):
2174-
self.msg.incompatible_setter_override(defn.items[1], typ, original_type, base)
2171+
self.msg.incompatible_setter_override(defn.setter, typ, original_type, base)
21752172

21762173
def check_method_override_for_base_with_name(
21772174
self, defn: FuncDef | OverloadedFuncDef | Decorator, name: str, base: TypeInfo
@@ -2860,29 +2857,6 @@ def check_multiple_inheritance(self, typ: TypeInfo) -> None:
28602857
if name in base2.names and base2 not in base.mro:
28612858
self.check_compatibility(name, base, base2, typ)
28622859

2863-
def determine_type_of_member(self, sym: SymbolTableNode) -> Type | None:
2864-
# TODO: this duplicates both checkmember.py and analyze_ref_expr(), delete.
2865-
if sym.type is not None:
2866-
return sym.type
2867-
if isinstance(sym.node, SYMBOL_FUNCBASE_TYPES):
2868-
return self.function_type(sym.node)
2869-
if isinstance(sym.node, TypeInfo):
2870-
if sym.node.typeddict_type:
2871-
# We special-case TypedDict, because they don't define any constructor.
2872-
return self.expr_checker.typeddict_callable(sym.node)
2873-
else:
2874-
return type_object_type(sym.node, self.named_type)
2875-
if isinstance(sym.node, TypeVarExpr):
2876-
# Use of TypeVars is rejected in an expression/runtime context, so
2877-
# we don't need to check supertype compatibility for them.
2878-
return AnyType(TypeOfAny.special_form)
2879-
if isinstance(sym.node, TypeAlias):
2880-
with self.msg.filter_errors():
2881-
# Suppress any errors, they will be given when analyzing the corresponding node.
2882-
# Here we may have incorrect options and location context.
2883-
return self.expr_checker.alias_type_in_runtime_context(sym.node, ctx=sym.node)
2884-
return None
2885-
28862860
def check_compatibility(
28872861
self, name: str, base1: TypeInfo, base2: TypeInfo, ctx: TypeInfo
28882862
) -> None:
@@ -3866,7 +3840,7 @@ def check_assignment_to_multiple_lvalues(
38663840
if rvalue_needed > 0:
38673841
rvalues = (
38683842
rvalues[0:iterable_start]
3869-
+ [TempNode(iterable_type) for i in range(rvalue_needed)]
3843+
+ [TempNode(iterable_type, context=rval) for _ in range(rvalue_needed)]
38703844
+ rvalues[iterable_end + 1 :]
38713845
)
38723846

@@ -7207,7 +7181,7 @@ def check_subtype(
72077181
if extra_info:
72087182
msg = msg.with_additional_msg(" (" + ", ".join(extra_info) + ")")
72097183

7210-
self.fail(msg, context)
7184+
error = self.fail(msg, context)
72117185
for note in notes:
72127186
self.msg.note(note, context, code=msg.code)
72137187
if note_msg:
@@ -7216,9 +7190,9 @@ def check_subtype(
72167190
if (
72177191
isinstance(supertype, Instance)
72187192
and supertype.type.is_protocol
7219-
and isinstance(subtype, (CallableType, Instance, TupleType, TypedDictType))
7193+
and isinstance(subtype, (CallableType, Instance, TupleType, TypedDictType, TypeType))
72207194
):
7221-
self.msg.report_protocol_problems(subtype, supertype, context, code=msg.code)
7195+
self.msg.report_protocol_problems(subtype, supertype, context, parent_error=error)
72227196
if isinstance(supertype, CallableType) and isinstance(subtype, Instance):
72237197
call = find_member("__call__", subtype, subtype, is_operator=True)
72247198
if call:
@@ -7547,12 +7521,11 @@ def temp_node(self, t: Type, context: Context | None = None) -> TempNode:
75477521

75487522
def fail(
75497523
self, msg: str | ErrorMessage, context: Context, *, code: ErrorCode | None = None
7550-
) -> None:
7524+
) -> ErrorInfo:
75517525
"""Produce an error message."""
75527526
if isinstance(msg, ErrorMessage):
7553-
self.msg.fail(msg.value, context, code=msg.code)
7554-
return
7555-
self.msg.fail(msg, context, code=code)
7527+
return self.msg.fail(msg.value, context, code=msg.code)
7528+
return self.msg.fail(msg, context, code=code)
75567529

75577530
def note(
75587531
self,

mypy/checker_shared.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
MypyFile,
2222
Node,
2323
RefExpr,
24-
TypeAlias,
24+
SymbolNode,
2525
TypeInfo,
2626
Var,
2727
)
@@ -64,10 +64,6 @@ def accept(
6464
def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
6565
raise NotImplementedError
6666

67-
@abstractmethod
68-
def module_type(self, node: MypyFile) -> Instance:
69-
raise NotImplementedError
70-
7167
@abstractmethod
7268
def check_call(
7369
self,
@@ -112,24 +108,26 @@ def check_method_call_by_name(
112108
) -> tuple[Type, Type]:
113109
raise NotImplementedError
114110

115-
@abstractmethod
116-
def alias_type_in_runtime_context(
117-
self, alias: TypeAlias, *, ctx: Context, alias_definition: bool = False
118-
) -> Type:
119-
raise NotImplementedError
120-
121111
@abstractmethod
122112
def visit_typeddict_index_expr(
123113
self, td_type: TypedDictType, index: Expression, setitem: bool = False
124114
) -> tuple[Type, set[str]]:
125115
raise NotImplementedError
126116

127117
@abstractmethod
128-
def typeddict_callable(self, info: TypeInfo) -> CallableType:
118+
def infer_literal_expr_type(self, value: LiteralValue, fallback_name: str) -> Type:
129119
raise NotImplementedError
130120

131121
@abstractmethod
132-
def infer_literal_expr_type(self, value: LiteralValue, fallback_name: str) -> Type:
122+
def analyze_static_reference(
123+
self,
124+
node: SymbolNode,
125+
ctx: Context,
126+
is_lvalue: bool,
127+
*,
128+
include_modules: bool = True,
129+
suppress_errors: bool = False,
130+
) -> Type:
133131
raise NotImplementedError
134132

135133

0 commit comments

Comments
 (0)