From 9138d86b13d07f031175f468d3979f439cef048a Mon Sep 17 00:00:00 2001 From: Bendaoud Date: Thu, 9 Oct 2025 10:42:18 +0200 Subject: [PATCH 1/2] test_scope_behavior.py --- mypy/test/test_scope_behavior.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 mypy/test/test_scope_behavior.py diff --git a/mypy/test/test_scope_behavior.py b/mypy/test/test_scope_behavior.py new file mode 100644 index 000000000000..142525391cdc --- /dev/null +++ b/mypy/test/test_scope_behavior.py @@ -0,0 +1,17 @@ +from mypy.scope import Scope +from mypy.nodes import FuncDef, TypeInfo, SymbolTable + +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" From 8f6c3c2aa1cb4588abdf2c9572ffacce07246123 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 08:46:36 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/test/test_scope_behavior.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/test/test_scope_behavior.py b/mypy/test/test_scope_behavior.py index 142525391cdc..074285b23c3c 100644 --- a/mypy/test/test_scope_behavior.py +++ b/mypy/test/test_scope_behavior.py @@ -1,5 +1,6 @@ +from mypy.nodes import FuncDef, SymbolTable, TypeInfo from mypy.scope import Scope -from mypy.nodes import FuncDef, TypeInfo, SymbolTable + def test_scope_module_and_function_behavior() -> None: scope = Scope()