Skip to content

Commit fdec444

Browse files
committed
ajout de la méthode without_function_locals dans scope.py
1 parent 4bbb618 commit fdec444

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mypy/scope.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,24 @@ def saved_scope(self, saved: SavedScope) -> Iterator[None]:
124124
with self.class_scope(info) if info else nullcontext():
125125
with self.function_scope(function) if function else nullcontext():
126126
yield
127+
128+
@contextmanager
129+
def without_function_locals(self):
130+
"""Temporarily disable the current function scope (used for nested class definitions)."""
131+
# Save current function
132+
saved_function = self.function
133+
saved_ignored = self.ignored
134+
saved_functions_stack = list(self.functions)
135+
136+
# Temporarily remove the current function scope
137+
self.function = None
138+
self.functions = []
139+
self.ignored = 0
140+
141+
try:
142+
yield
143+
finally:
144+
# Restore the previous function context
145+
self.function = saved_function
146+
self.functions = saved_functions_stack
147+
self.ignored = saved_ignored

0 commit comments

Comments
 (0)