-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-143504: Expose CELL status of a symbol in symtable #143549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b840e4e
0b676e4
2175829
17072bd
f096488
57b36be
5c558f4
19cd54d
a9e5bf7
f437b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -184,6 +184,7 @@ class Function(SymbolTable): | |||||||
| __frees = None | ||||||||
| __globals = None | ||||||||
| __nonlocals = None | ||||||||
| __cells = None | ||||||||
|
|
||||||||
| def __idents_matching(self, test_func): | ||||||||
| return tuple(ident for ident in self.get_identifiers() | ||||||||
|
|
@@ -229,6 +230,13 @@ def get_frees(self): | |||||||
| self.__frees = self.__idents_matching(is_free) | ||||||||
| return self.__frees | ||||||||
|
|
||||||||
| def get_cells(self): | ||||||||
| """Return a list of cell variable names in the table. | ||||||||
| """ | ||||||||
| if self.__cells is None: | ||||||||
| self.__cells = [s.get_name() for s in self.get_symbols() if s.is_cell()] | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's follow the pattern that it used in get_frees:
Suggested change
|
||||||||
| return self.__cells | ||||||||
|
|
||||||||
|
|
||||||||
| class Class(SymbolTable): | ||||||||
|
|
||||||||
|
|
@@ -342,6 +350,10 @@ def is_free(self): | |||||||
| """ | ||||||||
| return bool(self.__scope == FREE) | ||||||||
|
|
||||||||
| def is_cell(self): | ||||||||
| """Return *True* if the symbol is a cell variable.""" | ||||||||
| return bool(self.__scope == CELL) | ||||||||
|
|
||||||||
| def is_free_class(self): | ||||||||
| """Return *True* if a class-scoped symbol is free from | ||||||||
| the perspective of a method.""" | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -284,6 +284,10 @@ def test_local(self): | |||
| def test_free(self): | ||||
| self.assertTrue(self.internal.lookup("x").is_free()) | ||||
|
|
||||
| def test_cells(self): | ||||
| self.assertTrue(self.spam.lookup("x").is_cell()) | ||||
|
|
||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get_cells is not tested at all.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add it to test_function_info:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There ate 2 blanks instead of 1 here. |
||||
| def test_referenced(self): | ||||
| self.assertTrue(self.internal.lookup("x").is_referenced()) | ||||
| self.assertTrue(self.spam.lookup("internal").is_referenced()) | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add symtable.is_cell() and get_cells() methods for cell variable analysis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.