| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,6 +180,12 @@ Examining Symbol Tables | |||
| 180 | 180 | Return a tuple containing names of :term:`free (closure) variables <closure variable>` | |
| 181 | 181 | in this function. | |
| 182 | 182 | ||
| 183 | + .. method:: get_cells() | ||
| 184 | + | ||
| 185 | + Return a tuple containing names of :term:`cell variables <closure variable>` in this table. | ||
| 186 | + | ||
| 187 | + .. versionadded:: next | ||
| 188 | + | ||
| 183 | 189 | ||
| 184 | 190 | .. class:: Class | |
| 185 | 191 | ||
@@ -291,6 +297,12 @@ Examining Symbol Tables | |||
| 291 | 297 | Return ``True`` if the symbol is referenced in its block, but not assigned | |
| 292 | 298 | to. | |
| 293 | 299 | ||
| 300 | + .. method:: is_cell() | ||
| 301 | + | ||
| 302 | + Return ``True`` if the symbol is referenced but not assigned in a nested block. | ||
| 303 | + | ||
| 304 | + .. versionadded:: next | ||
| 305 | + | ||
| 294 | 306 | .. method:: is_free_class() | |
| 295 | 307 | ||
| 296 | 308 | Return *True* if a class-scoped symbol is free from | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -737,6 +737,13 @@ ssl | |||
| 737 | 737 | (Contributed by Ron Frederick in :gh:`138252`.) | |
| 738 | 738 | ||
| 739 | 739 | ||
| 740 | + symtable | ||
| 741 | + -------- | ||
| 742 | + | ||
| 743 | + * Add :meth:`symtable.Function.get_cells` and :meth:`symtable.Symbol.is_cell` methods. | ||
| 744 | + (Contributed by Yashp002 in :gh:`143504`.) | ||
| 745 | + | ||
| 746 | + | ||
| 740 | 747 | sys | |
| 741 | 748 | --- | |
| 742 | 749 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -184,6 +184,7 @@ class Function(SymbolTable): | |||
| 184 | 184 | __frees = None | |
| 185 | 185 | __globals = None | |
| 186 | 186 | __nonlocals = None | |
| 187 | + __cells = None | ||
| 187 | 188 | ||
| 188 | 189 | def __idents_matching(self, test_func): | |
| 189 | 190 | return tuple(ident for ident in self.get_identifiers() | |
@@ -229,6 +230,14 @@ def get_frees(self): | |||
| 229 | 230 | self.__frees = self.__idents_matching(is_free) | |
| 230 | 231 | return self.__frees | |
| 231 | 232 | ||
| 233 | + def get_cells(self): | ||
| 234 | + """Return a tuple of cell variables in the function. | ||
| 235 | + """ | ||
| 236 | + if self.__cells is None: | ||
| 237 | + is_cell = lambda x: _get_scope(x) == CELL | ||
| 238 | + self.__cells = self.__idents_matching(is_cell) | ||
| 239 | + return self.__cells | ||
| 240 | + | ||
| 232 | 241 | ||
| 233 | 242 | class Class(SymbolTable): | |
| 234 | 243 | ||
@@ -342,6 +351,10 @@ def is_free(self): | |||
| 342 | 351 | """ | |
| 343 | 352 | return bool(self.__scope == FREE) | |
| 344 | 353 | ||
| 354 | + def is_cell(self): | ||
| 355 | + """Return *True* if the symbol is a cell variable.""" | ||
| 356 | + return bool(self.__scope == CELL) | ||
| 357 | + | ||
| 345 | 358 | def is_free_class(self): | |
| 346 | 359 | """Return *True* if a class-scoped symbol is free from | |
| 347 | 360 | the perspective of a method.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,6 +255,7 @@ def test_function_info(self): | |||
| 255 | 255 | self.assertEqual(sorted(func.get_locals()), expected) | |
| 256 | 256 | self.assertEqual(sorted(func.get_globals()), ["bar", "glob", "some_assigned_global_var"]) | |
| 257 | 257 | self.assertEqual(self.internal.get_frees(), ("x",)) | |
| 258 | + self.assertEqual(self.spam.get_cells(), ("some_var", "x",)) | ||
| 258 | 259 | ||
| 259 | 260 | def test_globals(self): | |
| 260 | 261 | self.assertTrue(self.spam.lookup("glob").is_global()) | |
@@ -284,6 +285,9 @@ def test_local(self): | |||
| 284 | 285 | def test_free(self): | |
| 285 | 286 | self.assertTrue(self.internal.lookup("x").is_free()) | |
| 286 | 287 | ||
| 288 | + def test_cells(self): | ||
| 289 | + self.assertTrue(self.spam.lookup("x").is_cell()) | ||
| 290 | + | ||
| 287 | 291 | def test_referenced(self): | |
| 288 | 292 | self.assertTrue(self.internal.lookup("x").is_referenced()) | |
| 289 | 293 | self.assertTrue(self.spam.lookup("internal").is_referenced()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Add :meth:`symtable.Function.get_cells` and :meth:`symtable.Symbol.is_cell` methods. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments