Skip to content

Commit a6a5388

Browse files
committed
Minor fixes
1 parent a96c516 commit a6a5388

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ def __init__(self, names: 'SymbolTable', defn: ClassDef, module_name: str) -> No
19581958

19591959
def add_type_vars(self) -> None:
19601960
if self.defn.type_vars:
1961-
for vd in defn.type_vars:
1961+
for vd in self.defn.type_vars:
19621962
self.type_vars.append(vd.name)
19631963

19641964
def name(self) -> str:

mypy/semanal.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,13 @@ def refresh_top_level(self, file_node: MypyFile) -> None:
282282
self.accept(d)
283283

284284
def refresh_class_def(self, defn: ClassDef) -> None:
285-
with self.analyze_class_body(defn):
286-
for d in defn.defs.body:
287-
if isinstance(d, ClassDef):
288-
self.refresh_class_def(d)
289-
elif not isinstance(d, FuncItem):
290-
self.accept(d)
285+
with self.analyze_class_body(defn) as should_continue:
286+
if should_continue:
287+
for d in defn.defs.body:
288+
if isinstance(d, ClassDef):
289+
self.refresh_class_def(d)
290+
elif not isinstance(d, FuncItem):
291+
self.accept(d)
291292

292293
@contextmanager
293294
def file_context(self, file_node: MypyFile, fnam: str, options: Options,
@@ -617,16 +618,19 @@ def check_function_signature(self, fdef: FuncItem) -> None:
617618
self.fail('Type signature has too many arguments', fdef, blocker=True)
618619

619620
def visit_class_def(self, defn: ClassDef) -> None:
620-
with self.analyze_class_body(defn):
621-
# Analyze class body.
622-
defn.defs.accept(self)
621+
with self.analyze_class_body(defn) as should_continue:
622+
if should_continue:
623+
# Analyze class body.
624+
defn.defs.accept(self)
623625

624626
@contextmanager
625-
def analyze_class_body(self, defn: ClassDef) -> Iterator[None]:
627+
def analyze_class_body(self, defn: ClassDef) -> Iterator[bool]:
626628
self.clean_up_bases_and_infer_type_variables(defn)
627629
if self.analyze_typeddict_classdef(defn):
630+
yield False
628631
return
629632
if self.analyze_namedtuple_classdef(defn):
633+
yield False
630634
return
631635
self.setup_class_def_analysis(defn)
632636

@@ -640,7 +644,7 @@ def analyze_class_body(self, defn: ClassDef) -> Iterator[None]:
640644

641645
self.enter_class(defn)
642646

643-
yield
647+
yield True
644648

645649
self.calculate_abstract_status(defn.info)
646650
self.setup_type_promotion(defn)

mypy/server/aststrip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from mypy.nodes import (
77
Node, FuncDef, NameExpr, MemberExpr, RefExpr, MypyFile, FuncItem, ClassDef, AssignmentStmt,
8-
TypeInfo
8+
TypeInfo, Var
99
)
1010
from mypy.traverser import TraverserVisitor
1111

@@ -84,7 +84,6 @@ def strip_ref_expr(self, node: RefExpr) -> None:
8484
# TODO: handle more node types
8585

8686

87-
8887
def is_self_member_ref(memberexpr: MemberExpr) -> bool:
8988
"""Does memberexpr refer to an attribute of self?"""
9089
# TODO: Merge with is_self_member_ref in semanal.py.

mypy/server/target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Iterable, Tuple
1+
from typing import Iterable, Tuple, List
22

33

44
def module_prefix(modules: Iterable[str], target: str) -> str:
55
return split_target(modules, target)[0]
66

77

88
def split_target(modules: Iterable[str], target: str) -> Tuple[str, str]:
9-
remaining = []
9+
remaining = [] # type: List[str]
1010
while True:
1111
if target in modules:
1212
return target, '.'.join(remaining)

mypy/server/update.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,17 +393,18 @@ def lookup_target(modules: Dict[str, MypyFile], target: str) -> List[DeferredNod
393393
active_class = node
394394
active_class_name = node.name()
395395
# TODO: Is it possible for the assertion to fail?
396-
assert isinstance(node, (MypyFile, TypeInfo))
397396
if isinstance(node, MypyFile):
398397
file = node
398+
assert isinstance(node, (MypyFile, TypeInfo))
399399
node = node.names[c].node
400400
if isinstance(node, TypeInfo):
401401
# A ClassDef target covers the body of the class and everything defined
402402
# within it. To get the body we include the entire surrounding target,
403403
# typically a module top-level, since we don't support processing class
404404
# bodies as separate entitites for simplicity.
405405
result = [DeferredNode(file, None, None)]
406-
for name, node in node.names.items():
406+
for name, symnode in node.names.items():
407+
node = symnode.node
407408
if isinstance(node, FuncDef):
408409
result.extend(lookup_target(modules, target + '.' + name))
409410
return result

test-data/unit/semanal-typeinfo.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ TypeInfoMap(
99
__main__.c : TypeInfo(
1010
Name(__main__.c)
1111
Bases(builtins.object)
12+
Mro(__main__.c, builtins.object)
1213
Names()))
1314

1415
[case testClassWithMethod]
@@ -19,6 +20,7 @@ TypeInfoMap(
1920
__main__.c : TypeInfo(
2021
Name(__main__.c)
2122
Bases(builtins.object)
23+
Mro(__main__.c, builtins.object)
2224
Names(
2325
f)))
2426

@@ -32,6 +34,7 @@ TypeInfoMap(
3234
__main__.c : TypeInfo(
3335
Name(__main__.c)
3436
Bases(builtins.object)
37+
Mro(__main__.c, builtins.object)
3538
Names(
3639
__init__
3740
y
@@ -45,10 +48,12 @@ TypeInfoMap(
4548
__main__.base : TypeInfo(
4649
Name(__main__.base)
4750
Bases(builtins.object)
51+
Mro(__main__.base, builtins.object)
4852
Names())
4953
__main__.c : TypeInfo(
5054
Name(__main__.c)
5155
Bases(__main__.base)
56+
Mro(__main__.c, __main__.base, builtins.object)
5257
Names()))
5358

5459
[case testClassAndAbstractClass]
@@ -62,10 +67,12 @@ TypeInfoMap(
6267
__main__.c : TypeInfo(
6368
Name(__main__.c)
6469
Bases(__main__.i)
70+
Mro(__main__.c, __main__.i, builtins.object)
6571
Names())
6672
__main__.i : TypeInfo(
6773
Name(__main__.i)
6874
Bases(builtins.object)
75+
Mro(__main__.i, builtins.object)
6976
Names()))
7077

7178
[case testAttributeWithoutType]
@@ -76,5 +83,6 @@ TypeInfoMap(
7683
__main__.A : TypeInfo(
7784
Name(__main__.A)
7885
Bases(builtins.object)
86+
Mro(__main__.A, builtins.object)
7987
Names(
8088
a)))

0 commit comments

Comments
 (0)