Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mypy/test/test_scope_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from mypy.nodes import FuncDef, SymbolTable, TypeInfo
from mypy.scope import Scope


def test_scope_module_and_function_behavior() -> None:
scope = Scope()
with scope.module_scope("mod1"):
assert scope.current_module_id() == "mod1"
# simulate function
fake_func = FuncDef("f", None, None, None, None)
with scope.function_scope(fake_func):
assert "f" in scope.current_full_target()
# simulate class inside function
fake_class = TypeInfo(SymbolTable(), "C", None)
with scope.class_scope(fake_class):
assert "C" in scope.current_full_target()
# leaving function restores module
assert scope.current_full_target() == "mod1"
Loading