File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments