Skip to content

Commit e904af4

Browse files
committed
Respond to first wave (wavelet?) of feedback
This commit contains mainly more fixups and refactoring in response to the first wave[let] of feedback.
1 parent 4f621f2 commit e904af4

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

mypy/checkexpr.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ def __init__(self,
100100
self.msg = msg
101101
self.strfrm_checker = StringFormatterChecker(self, self.chk, self.msg)
102102

103-
def _visit_typeinfo(self, info: nodes.TypeInfo) -> None:
104-
if info is not None:
105-
self.chk.module_refs.update(split_module_names(info.module_name))
106-
107103
def visit_name_expr(self, e: NameExpr) -> Type:
108104
"""Type check a name expression.
109105

mypy/indirection.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Set, Iterable
1+
from typing import Dict, Iterable, List, Optional, Set
22
from abc import abstractmethod
33

44
from mypy.visitor import NodeVisitor
@@ -9,12 +9,14 @@
99
from mypy.util import split_module_names
1010

1111

12-
def extract_module_names(type_name: Optional[str]) -> Iterable[str]:
13-
"""Returns the module name of a fully qualified type name."""
12+
def extract_module_names(type_name: Optional[str]) -> List[str]:
13+
"""Returns the module names of a fully qualified type name."""
1414
if type_name is not None:
15-
while '.' in type_name:
16-
type_name = type_name.rsplit('.', 1)[0]
17-
yield type_name
15+
# Discard the first one, which is just the qualified name of the type
16+
possible_module_names = split_module_names(type_name)
17+
return possible_module_names[1:]
18+
else:
19+
return []
1820

1921

2022
class TypeIndirectionVisitor(TypeVisitor[Set[str]]):

mypy/nodes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ class Var(SymbolNode, Statement):
585585
is_settable_property = False
586586
# Set to true when this variable refers to a module we were unable to
587587
# parse for some reason (eg a silenced module)
588-
is_import = False
588+
is_suppressed_import = False
589589

590590
def __init__(self, name: str, type: 'mypy.types.Type' = None) -> None:
591591
self._name = name
@@ -616,7 +616,7 @@ def serialize(self) -> JsonDict:
616616
'is_classmethod': self.is_classmethod,
617617
'is_property': self.is_property,
618618
'is_settable_property': self.is_settable_property,
619-
'is_import': self.is_import,
619+
'is_suppressed_import': self.is_suppressed_import,
620620
} # type: JsonDict
621621
return data
622622

@@ -633,7 +633,7 @@ def deserialize(cls, data: JsonDict) -> 'Var':
633633
v.is_classmethod = data['is_classmethod']
634634
v.is_property = data['is_property']
635635
v.is_settable_property = data['is_settable_property']
636-
v.is_import = data['is_import']
636+
v.is_suppressed_import = data['is_suppressed_import']
637637
return v
638638

639639

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ def add_unknown_symbol(self, name: str, context: Context, is_import: bool = Fals
10501050
var._fullname = self.qualified_name(name)
10511051
var.is_ready = True
10521052
var.type = AnyType()
1053-
var.is_import = is_import
1053+
var.is_suppressed_import = is_import
10541054
self.add_symbol(name, SymbolTableNode(GDEF, var, self.cur_mod_id), context)
10551055

10561056
#

mypy/util.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
import subprocess
5-
from typing import TypeVar, List, Any, Tuple, Optional, Iterable
5+
from typing import TypeVar, List, Any, Tuple, Optional
66

77

88
T = TypeVar('T')
@@ -12,15 +12,17 @@
1212
default_python2_interpreter = ['python2', 'python', '/usr/bin/python']
1313

1414

15-
def split_module_names(mod_name: str) -> Iterable[str]:
16-
"""Yields the module and all parent module names.
15+
def split_module_names(mod_name: str) -> List[str]:
16+
"""Return the module and all parent module names.
1717
18-
So, if `mod_name` is 'a.b.c', this function will yield
19-
['a.b.c', 'a.b', and 'a']."""
20-
yield mod_name
18+
So, if `mod_name` is 'a.b.c', this function will return
19+
['a.b.c', 'a.b', and 'a'].
20+
"""
21+
out = [mod_name]
2122
while '.' in mod_name:
2223
mod_name = mod_name.rsplit('.', 1)[0]
23-
yield mod_name
24+
out.append(mod_name)
25+
return out
2426

2527

2628
def short_type(obj: object) -> str:

0 commit comments

Comments
 (0)