Skip to content

Commit 9138d86

Browse files
committed
test_scope_behavior.py
1 parent 3807423 commit 9138d86

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mypy/test/test_scope_behavior.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from mypy.scope import Scope
2+
from mypy.nodes import FuncDef, TypeInfo, SymbolTable
3+
4+
def test_scope_module_and_function_behavior() -> None:
5+
scope = Scope()
6+
with scope.module_scope("mod1"):
7+
assert scope.current_module_id() == "mod1"
8+
# simulate function
9+
fake_func = FuncDef("f", None, None, None, None)
10+
with scope.function_scope(fake_func):
11+
assert "f" in scope.current_full_target()
12+
# simulate class inside function
13+
fake_class = TypeInfo(SymbolTable(), "C", None)
14+
with scope.class_scope(fake_class):
15+
assert "C" in scope.current_full_target()
16+
# leaving function restores module
17+
assert scope.current_full_target() == "mod1"

0 commit comments

Comments
 (0)