Skip to content

Commit

Permalink
New analyzer: test that class properties are calculated for classes i…
Browse files Browse the repository at this point in the history
…n functions (#7147)

Fixes #6494

The issue seems to be already fixed because of how `local_definitions()` works, I just add a test case to avoid regressions.
  • Loading branch information
ilevkivskyi committed Jul 4, 2019
1 parent 496bb64 commit 6d70615
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def visit_func_def(self, defn: FuncDef) -> None:
self.statement = defn
defn.is_conditional = self.block_depth[-1] > 0

# Set full names even for those definitionss that aren't added
# Set full names even for those definitions that aren't added
# to a symbol table. For example, for overload items.
defn._fullname = self.qualified_name(defn.name())

Expand Down
1 change: 0 additions & 1 deletion mypy/newsemanal/semanal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def calculate_class_properties(graph: 'Graph', scc: List[str], errors: Errors) -
for module in scc:
tree = graph[module].tree
assert tree
# TODO: calculate properties also for classes nested in functions.
for _, node, _ in tree.local_definitions():
if isinstance(node.node, TypeInfo):
saved = (module, node.node, None) # module, class, function
Expand Down
24 changes: 24 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -2968,3 +2968,27 @@ reveal_type(C) # N: Revealed type is 'Any' \
from typing import Final
x: Final = 0
x = x # E: Cannot assign to final name "x"

[case testNewAnalyzerClassPropertiesInAllScopes]
from abc import abstractmethod, ABCMeta

class TopLevel(metaclass=ABCMeta):
@abstractmethod
def f(self) -> None: pass

TopLevel() # E: Cannot instantiate abstract class 'TopLevel' with abstract attribute 'f'

def func() -> None:
class Function(metaclass=ABCMeta):
@abstractmethod
def f(self) -> None: pass

Function() # E: Cannot instantiate abstract class 'Function' with abstract attribute 'f'

class C:
def meth(self) -> None:
class Method(metaclass=ABCMeta):
@abstractmethod
def f(self) -> None: pass

Method() # E: Cannot instantiate abstract class 'Method' with abstract attribute 'f'

0 comments on commit 6d70615

Please sign in to comment.