8000 Merge branch 'master' into fix-synthetic-crashes · python/mypy@9779103 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9779103

Browse files
authored
Merge branch 'master' into fix-synthetic-crashes
2 parents 9f92b0f + 3db1451 commit 9779103

21 files changed

+832
-117
lines changed

CREDITS

Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,31 @@
11
Credits
22
-------
33

4-
Lead developer:
4+
For a full list of contributors you can mine the commit history:
5+
https://github.com/python/mypy/commits/master
6+
7+
For lists of contributors per mypy release (including typeshed) see
8+
the release blog posts at https://mypy-lang.blogspot.com/.
9+
10+
Mypy team:
511

612
Jukka Lehtosalo <jukka.lehtosalo@iki.fi>
13+
Guido van Rossum <guido@python.org>
714

8-
Core team:
15+
Past Dropbox core team members:
916

10-
Guido <guido@dropbox.com>
11-
David Fisher <ddfisher@dropbox.com>
12-
Greg Price <gregprice@dropbox.com>
17+
David Fisher
18+
Svyatoslav Ilinskiy
19+
Greg Price
20+
Naomi Seyfer
21+
Michael Lee
22+
Reid Barton
1323

14-
Contributors (in alphabetical order, including typeshed):
24+
Non-Dropbox core team members:
1525

16-
Tim Abbott
17-
Steven Allen (@Stebalien)
18-
Della Anjeh
19-
Reid Barton (@rwbarton)
20-
Matthias Bussonnier
21-
Anup Chenthamarakshan
22-
Kyle Consalus
23-
Ian Cordasco
24-
ctcutler
25-
Ben Darnell
26-
Miguel Garcia (@rockneurotiko)
27-
Mihnea Giurgea
28-
Ryan Gonzalez (@kirbyfan64)
29-
James Guthrie
30-
Jared Hance
31-
Ashley Hewson (@ashleyh)
32-
icoxfog417
33-
Bob Ippolito (@etrepum)
34-
ismail-s
35-
Sander Kersten (@spkersten)
36-
Matthias Kramm
37-
Ian Kronquist (@iankronquist)
38-
Yuval Langer
39-
Howard Lee
40-
Tad Leonard
41-
Li Haoyi
42-
Darjus Loktevic
43-
Ben Longbons
44-
Florian Ludwig (@FlorianLudwig)
45-
Robert T. McGibbon
46-
Ron Murawski <ron@horizonchess.com>
47-
Motoki Naruse
48-
Jared Pochtar (@jaredp)
49-
Michal Pokorný
50-
Eric Price (@ecprice)
51-
Brodie Rao
52-
Sebastian Reuße
53-
Sebastian Riikonen
54-
Seo Sanghyeon
55-
Marek Sapota
56-
Gigi Sayfan
57-
Vlad Shcherbina
58-
Anders Schuller
59-
Daniel Shaulov
60-
David Shea
61-
Vita Smid
62-
Schuyler Smith
63-
Marcell Vazquez-Chanlatte (@mvcisback)
64-
Prayag Verma
65-
Igor Vuk (@ivuk)
66-
Jeff Walden (@jswalden)
67-
Michael Walter
68-
Jing Wang
69-
Wen Zhang
70-
Roy Williams
71-
wizzardx
72-
Matthew Wright
73-
Yuanchao Zhu (@yczhu)
74-
Gennadiy Zlobin (@gennad)
26+
Ivan Levkivskyi
27+
Ethan Smith
28+
Jelle Zijlstra
7529

7630
Additional thanks to:
7731

mypy/checker.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,13 +1015,13 @@ def expand_typevars(self, defn: FuncItem,
10151015
else:
10161016
return [(defn, typ)]
10171017

1018-
def check_method_override(self, defn: FuncBase) -> None:
1018+
def check_method_override(self, defn: Union[FuncBase, Decorator]) -> None:
10191019
"""Check if function definition is compatible with base classes."""
10201020
# Check against definitions in base classes.
10211021
for base in defn.info.mro[1:]:
10221022
self.check_method_or_accessor_override_for_base(defn, base)
10231023

1024-
def check_method_or_accessor_override_for_base(self, defn: FuncBase,
1024+
def check_method_or_accessor_override_for_base(self, defn: Union[FuncBase, Decorator],
10251025
base: TypeInfo) -> None:
10261026
"""Check if method definition is compatible with a base class."""
10271027
if base:
@@ -1041,13 +1041,26 @@ def check_method_or_accessor_override_for_base(self, defn: FuncBase,
10411041
base)
10421042

10431043
def check_method_override_for_base_with_name(
1044-
self, defn: FuncBase, name: str, base: TypeInfo) -> None:
1044+
self, defn: Union[FuncBase, Decorator], name: str, base: TypeInfo) -> None:
10451045
base_attr = base.names.get(name)
10461046
if base_attr:
10471047
# The name of the method is defined in the base class.
10481048

1049+
# Point errors at the 'def' line (important for backward compatibility
1050+
# of type ignores).
1051+
if not isinstance(defn, Decorator):
1052+
context = defn
1053+
else:
1054+
context = defn.func
10491055
# Construct the type of the overriding method.
1050-
typ = bind_self(self.function_type(defn), self.scope.active_self_type())
1056+
if isinstance(defn, FuncBase):
1057+
typ = self.function_type(defn) # type: Type
1058+
else:
1059+
assert defn.var.is_ready
1060+
assert defn.var.type is not None
1061+
typ = defn.var.type
1062+
if isinstance(typ, FunctionLike) and not is_static(context):
1063+
typ = bind_self(typ, self.scope.active_self_type())
10511064
# Map the overridden method type to subtype context so that
10521065
# it can be checked for compatibility.
10531066
original_type = base_attr.type
@@ -1058,23 +1071,33 @@ def check_method_override_for_base_with_name(
10581071
original_type = self.function_type(base_attr.node.func)
10591072
else:
10601073
assert False, str(base_attr.node)
1061-
if isinstance(original_type, FunctionLike):
1062-
original = map_type_from_supertype(
1063-
bind_self(original_type, self.scope.active_self_type()),
1064-
defn.info, base)
1074+
if isinstance(original_type, AnyType) or isinstance(typ, AnyType):
1075+
pass
1076+
elif isinstance(original_type, FunctionLike) and isinstance(typ, FunctionLike):
1077+
if (isinstance(base_attr.node, (FuncBase, Decorator))
1078+
and not is_static(base_attr.node)):
1079+
bound = bind_self(original_type, self.scope.active_self_type())
1080+
else:
1081+
bound = original_type
1082+
original = map_type_from_supertype(bound, defn.info, base)
10651083
# Check that the types are compatible.
10661084
# TODO overloaded signatures
10671085
self.check_override(typ,
10681086
cast(FunctionLike, original),
10691087
defn.name(),
10701088
name,
10711089
base.name(),
1072-
defn)
1073-
elif isinstance(original_type, AnyType):
1090+
context)
1091+
elif is_equivalent(original_type, typ):
1092+
# Assume invariance for a non-callable attribute here. Note
1093+
# that this doesn't affect read-only properties which can have
1094+
# covariant overrides.
1095+
#
1096+
# TODO: Allow covariance for read-only attributes?
10741097
pass
10751098
else:
10761099
self.msg.signature_incompatible_with_supertype(
1077-
defn.name(), name, base.name(), defn)
1100+
defn.name(), name, base.name(), context)
10781101

10791102
def check_override(self, override: FunctionLike, original: FunctionLike,
10801103
name: str, name_in_super: str, supertype: str,
@@ -1966,7 +1989,7 @@ def try_infer_partial_type_from_indexed_assignment(
19661989
if not self.current_node_deferred:
19671990
var.type = self.named_generic_type('builtins.dict',
19681991
[full_key_type, full_value_type])
1969-
del partial_types[var]
1992+
del partial_types[var]
19701993

19711994
def visit_expression_stmt(self, s: ExpressionStmt) -> None:
19721995
self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
@@ -2015,7 +2038,7 @@ def check_return_stmt(self, s: ReturnStmt) -> None:
20152038
# function is not declared to return Any)
20162039
if (self.options.warn_return_any and
20172040
not is_proper_subtype(AnyType(TypeOfAny.special_form), return_type)):
2018-
self.warn(messages.RETURN_ANY.format(return_type), s)
2041+
self.msg.incorrectly_returning_any(return_type, s)
20192042
return
20202043

20212044
# Disallow return expressions in functions declared to return
@@ -2364,9 +2387,11 @@ def visit_decorator(self, e: Decorator) -> None:
23642387
e.var.is_ready = True
23652388
return
23662389

2367-
e.func.accept(self)
2390+
self.check_func_item(e.func, name=e.func.name())
2391+
2392+
# Process decorators from the inside out to determine decorated signature, which
2393+
# may be different from the declared signature.
23682394
sig = self.function_type(e.func) # type: Type
2369-
# Process decorators from the inside out.
23702395
for d in reversed(e.decorators):
23712396
if refers_to_fullname(d, 'typing.overload'):
23722397
self.fail('Single overload definition, multiple required', e)
@@ -2387,6 +2412,8 @@ def visit_decorator(self, e: Decorator) -> None:
23872412
e.var.is_ready = True
23882413
if e.func.is_property:
23892414
self.check_incompatible_property_override(e)
2415+
if e.func.info and not e.func.is_dynamic():
2416+
self.check_method_override(e)
23902417

23912418
def check_for_untyped_decorator(self,
23922419
func: FuncDef,
@@ -3316,3 +3343,13 @@ def is_untyped_decorator(typ: Optional[Type]) -> bool:
33163343
if not typ or not isinstance(typ, CallableType):
33173344
return True
33183345
return typ.implicit
3346+
3347+
3348+
def is_static(func: Union[FuncBase, Decorator]) -> bool:
3349+
if isinstance(func, Decorator):
3350+
return is_static(func.func)
3351+
elif isinstance(func, OverloadedFuncDef):
3352+
return any(is_static(item) for item in func.items)
3353+
elif isinstance(func, FuncItem):
3354+
return func.is_static
3355+
return False

0 commit comments

Comments
 (0)
0