Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class Function(SymbolTable):
__frees = None
__globals = None
__nonlocals = None
__cells = None
Comment thread
iritkatriel marked this conversation as resolved.

def __idents_matching(self, test_func):
return tuple(ident for ident in self.get_identifiers()
Expand Down Expand Up @@ -230,8 +231,11 @@ def get_frees(self):
return self.__frees

def get_cells(self):
"""Return a list of cell variable names in the table."""
return [s.get_name() for s in self.get_symbols() if s.is_cell()]
"""Return a list of cell variable names in the table.
Comment thread
Yashp002 marked this conversation as resolved.
Outdated
"""
if self.__cells is None:
self.__cells = [s.get_name() for s in self.get_symbols() if s.is_cell()]
Comment thread
Yashp002 marked this conversation as resolved.
Outdated
return self.__cells


Comment thread
Yashp002 marked this conversation as resolved.
class Class(SymbolTable):
Expand Down
14 changes: 2 additions & 12 deletions Lib/test/test_symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,8 @@ def test_free(self):
self.assertTrue(self.internal.lookup("x").is_free())

def test_cells(self):
#test for addition of is_cell() and get_cells()
#see https://github.com/python/cpython/issues/143504
code="""def outer():
x=1
def inner():
return x"""

top=symtable.symtable(code,"?","exec")
outer = find_block(top, "outer")
self.assertIn("x",outer.get_cells())
self.assertTrue(outer.lookup("x").is_cell())
self.assertFalse(outer.lookup("inner").is_cell())
self.assertTrue(self.spam.lookup("x").is_cell())


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_cells is not tested at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to test_function_info:

@@ -255,6 +255,7 @@ def test_function_info(self):
         self.assertEqual(sorted(func.get_locals()), expected)
         self.assertEqual(sorted(func.get_globals()), ["bar", "glob", "some_assigned_global_var"])
         self.assertEqual(self.internal.get_frees(), ("x",))
+        self.assertEqual(self.spam.get_cells(), ("some_var", "x",))

Comment thread
Yashp002 marked this conversation as resolved.
Outdated
def test_referenced(self):
self.assertTrue(self.internal.lookup("x").is_referenced())
Expand Down
Loading