File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,6 +184,7 @@ class Function(SymbolTable):
184184 __frees = None
185185 __globals = None
186186 __nonlocals = None
187+ __cells = None
187188
188189 def __idents_matching (self , test_func ):
189190 return tuple (ident for ident in self .get_identifiers ()
@@ -230,8 +231,11 @@ def get_frees(self):
230231 return self .__frees
231232
232233 def get_cells (self ):
233- """Return a list of cell variable names in the table."""
234- return [s .get_name () for s in self .get_symbols () if s .is_cell ()]
234+ """Return a list of cell variable names in the table.
235+ """
236+ if self .__cells is None :
237+ self .__cells = [s .get_name () for s in self .get_symbols () if s .is_cell ()]
238+ return self .__cells
235239
236240
237241class Class (SymbolTable ):
Original file line number Diff line number Diff line change @@ -285,16 +285,15 @@ def test_free(self):
285285 self .assertTrue (self .internal .lookup ("x" ).is_free ())
286286
287287 def test_cells (self ):
288- #test for addition of is_cell() and get_cells()
289- #see https://github.com/python/cpython/issues/143504
288+
290289 code = """def outer():
291290 x=1
292291 def inner():
293292 return x"""
294293
295294 top = symtable .symtable (code ,"?" ,"exec" )
296295 outer = find_block (top , "outer" )
297- self .assertIn ( "x" , outer .get_cells ())
296+ self .assertEqual ( outer .get_cells (), [ "x" ] )
298297 self .assertTrue (outer .lookup ("x" ).is_cell ())
299298 self .assertFalse (outer .lookup ("inner" ).is_cell ())
300299
You can’t perform that action at this time.
0 commit comments