GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-143504: Expose CELL status of a symbol in symtable by Yashp002 · Pull Request #143549 · python/cpython

Conversation

@Yashp002

@Yashp002 Yashp002 commented Jan 8, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Expose cell status in symtable.Symbol via new is_cell() predicate and add get_cells() method to SymbolTable.

Changes

  • Added Symbol.is_cell() method that returns True if the symbol has the CELL flag.
  • Added SymbolTable.get_cells() method that returns an iterable of cell variable names.
  • Added test_cells to Lib/test/test_symtable.py to verify the new API.

Tests

  • Added test_cells test using a closure pattern (outer -> inner accessing x).
  • Issue: expose CELL status of a symbol in symtable #143504

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Yashp002
symtable commit
b840e4e
@bedevere-app bedevere-app Bot added the awaiting review label Jan 8, 2026
@Yashp002 Yashp002 changed the title bpo-143504: Expose CELL status of a symbol in symtable (GH-143504) gh-143504: Expose CELL status of a symbol in symtable (GH-143504) Jan 8, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Jan 8, 2026
expose CELL status of a symbol in symtable #143504
Closed
aisk
aisk reviewed Jan 8, 2026
View reviewed changes
Comment thread Lib/symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Yashp002 and others added 2 commits January 8, 2026 16:17
@Yashp002 @aisk
symtable fix 1
0b676e4
Co-authored-by: AN Long <[email protected]>
@Yashp002
symtable fix 2- news
2175829
@Yashp002

Yashp002 commented Jan 8, 2026

Copy link
Copy Markdown
Contributor Author

I'll fix this in a while, my apologies for quite a big fault in the code actually

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Yashp002 added 2 commits January 21, 2026 15:51
@Yashp002
symtable fix 3
17072bd
@Yashp002
symtable fix 4
f096488
iritkatriel
iritkatriel reviewed Jan 21, 2026
View reviewed changes
Comment thread Lib/test/test_symtable.py Outdated
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())

@iritkatriel iritkatriel Jan 21, 2026

Copy link
Copy Markdown
Member

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.

Let's put this test next to test_free.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel
iritkatriel reviewed Jan 21, 2026
View reviewed changes
Comment thread Lib/symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel reviewed Jan 21, 2026
View reviewed changes
Comment thread Lib/symtable.py Outdated

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()]

@iritkatriel iritkatriel Jan 21, 2026

Copy link
Copy Markdown
Member

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.

This probably belongs next to get_frees.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Yashp002 added 2 commits January 21, 2026 23:27
@Yashp002
symtable fix 5
57b36be
@Yashp002
symtable fix 5
5c558f4
@Yashp002
Yashp002 force-pushed the symtable branch from bb93117 to 5c558f4 Compare January 21, 2026 18:00
@Yashp002

Yashp002 commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

@iritkatriel I was forced to force push the symtable branch due to me updating the branch before for the CI.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Yashp002
Merge branch 'main' into symtable
19cd54d
iritkatriel
iritkatriel reviewed Jan 21, 2026
View reviewed changes
Comment thread Lib/symtable.py Outdated

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()]

@iritkatriel iritkatriel Jan 21, 2026

Copy link
Copy Markdown
Member

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.

Why does this not follow the pattern of get_frees and get_nonlocals?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yashp002 Yashp002 Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

We'll have to use the _cells variable then, I'll add it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel
iritkatriel reviewed Jan 21, 2026
View reviewed changes
Comment thread Lib/test/test_symtable.py Outdated
code="""def outer():
x=1
def inner():
return x"""

@iritkatriel iritkatriel Jan 21, 2026

Copy link
Copy Markdown
Member

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.

the other tests don't do all this. Can we follow the same pattern in this one?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yashp002 Yashp002 Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

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.

@iritkatriel I've implemented the change in symtable.py with get_cells

But the current test_cells seems to be the only one that keeps working after I've change it up quite a few times.

Is it really a requirement for it all to have the same pattern?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Jan 21, 2026

Copy link
Copy Markdown
Member

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.

Unless there's a reason why we can't, then we should follow the same pattern. What's the difference between the cases?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yashp002 Yashp002 Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

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.

self.internal has x as FREE var (for test_free). we need x as CELL var (outer scope). setUp doesn't have that so inline code is needed. However I've removed the unnecessary comments and changed the rest of it to

    top=symtable.symtable(code,"?","exec")
    outer = find_block(top, "outer")
    self.assertEqual(outer.get_cells(), ["x"])
    self.assertTrue(outer.lookup("x").is_cell())
    self.assertFalse(outer.lookup("inner").is_cell()) to use assert.Equal,true and false like the rest of the functions.
    
    WOuld this be satisfactory as a commit?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Jan 23, 2026

Copy link
Copy Markdown
Member

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.

self.spam.lookup("x").is_cell()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Jan 23, 2026

Copy link
Copy Markdown
Member

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.

and get_cells test should be next to get_frees test.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yashp002 Yashp002 Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

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.

and get_cells test should be next to get_frees test.

isn't test_cells already next to test_free?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Yashp002 added 2 commits January 22, 2026 15:53
@Yashp002
symtable fix 6
a9e5bf7
@Yashp002
symtable fix 6
f437b13
iritkatriel
iritkatriel reviewed Jan 23, 2026
View reviewed changes
Comment thread Lib/test/test_symtable.py Outdated
self.assertFalse(outer.lookup("inner").is_cell())
self.assertTrue(self.spam.lookup("x").is_cell())


@iritkatriel iritkatriel Jan 23, 2026

Copy link
Copy Markdown
Member

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.

get_cells is not tested at all.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iritkatriel iritkatriel Jan 23, 2026

Copy link
Copy Markdown
Member

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.

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",))

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel
iritkatriel reviewed Jan 23, 2026
View reviewed changes
Comment thread Lib/symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Jan 23, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Can you also update symtable.rst? and add a What's New entry? (I did so for what I changed in 3.14)

And once you update the docs, update the NEWS entry to point them to

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Jan 23, 2026
View reviewed changes
Comment thread Lib/symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz changed the title gh-143504: Expose CELL status of a symbol in symtable (GH-143504) gh-143504: Expose CELL status of a symbol in symtable Jan 23, 2026
Yashp002 and others added 3 commits January 24, 2026 13:24
@Yashp002 @iritkatriel
symtable fix 7
54c8de1
Co-authored-by: Irit Katriel <[email protected]>
@Yashp002 @picnixz
symtable fix 8
3732812
Co-authored-by: Bénédikt Tran <[email protected]>
@Yashp002 @picnixz
symtable fix 8
d36cd84
Co-authored-by: Bénédikt Tran <[email protected]>
iritkatriel
iritkatriel reviewed Jan 24, 2026
View reviewed changes
Comment thread Doc/library/symtable.rst Outdated

.. method:: get_cells()

Return a tuple containing the names of cell variables in this table.

@iritkatriel iritkatriel Jan 24, 2026

Copy link
Copy Markdown
Member

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.

try formatting like the entry for get_frees with :term:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Yashp002
symtable fix 9
611d4d3
@Yashp002
Yashp002 requested a review from AA-Turner as a code owner January 24, 2026 11:39
Yashp002 added 2 commits January 24, 2026 17:16
@Yashp002
symtable fix 10
700a24f
@Yashp002
symtable fix 10
2b96cb5
iritkatriel
iritkatriel reviewed Jan 24, 2026
View reviewed changes
Comment thread Doc/library/symtable.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel reviewed Jan 24, 2026
View reviewed changes
Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-01-08-16-28-03.gh-issue-143504.PlC_Yv.rst Outdated
@@ -0,0 +1 @@
Add symtable.is_cell() and get_cells() methods for cell variable analysis.

@iritkatriel iritkatriel Jan 24, 2026

Copy link
Copy Markdown
Member

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.

There are two News files now

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Yashp002 and others added 4 commits January 24, 2026 20:56
@Yashp002 @iritkatriel
symtable fix
8c3a597
Co-authored-by: Irit Katriel <[email protected]>
@Yashp002 @iritkatriel
Update Doc/whatsnew/3.15.rst
b36df01
Co-authored-by: Irit Katriel <[email protected]>
@Yashp002
symtable fix 11
2539357
@Yashp002
symtable fix 11
b8df659
picnixz
picnixz reviewed Jan 24, 2026
View reviewed changes
Comment thread Doc/library/symtable.rst
Return a tuple containing names of :term:`free (closure) variables <closure variable>`
in this function.

.. method:: get_cells()

@picnixz picnixz Jan 24, 2026

Copy link
Copy Markdown
Member

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.

Please add the versionadded directive as well

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/symtable.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Library/2026-01-24-13-49-05.gh-issue-143594.nilGlg.rst Outdated
@@ -0,0 +1,2 @@
Add :meth:`symtable.Function.get_cells` and :meth:`symtable.Symbol.is_cell` methods.

@picnixz picnixz Jan 24, 2026

Copy link
Copy Markdown
Member

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.

Remove the extra empty line

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Yashp002 and others added 3 commits January 25, 2026 12:22
@Yashp002 @picnixz
Update Doc/library/symtable.rst
68653ee
Co-authored-by: Bénédikt Tran <[email protected]>
@Yashp002
symtable fix 12
6a6da41
@Yashp002
symtable fix 12
b5e8482
iritkatriel
iritkatriel reviewed Jan 25, 2026
View reviewed changes
Comment thread Lib/symtable.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel reviewed Jan 25, 2026
View reviewed changes
Comment thread Doc/library/symtable.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Yashp002 and others added 2 commits January 25, 2026 18:44
@Yashp002 @iritkatriel
Update Lib/symtable.py
14a6c28
Co-authored-by: Irit Katriel <[email protected]>
@Yashp002 @iritkatriel
Update Doc/library/symtable.rst
a8bb25a
Co-authored-by: Irit Katriel <[email protected]>
iritkatriel
iritkatriel approved these changes Jan 25, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jan 25, 2026
@iritkatriel
Merge branch 'main' into symtable
43b3cfc
@iritkatriel

iritkatriel commented Jan 25, 2026

Copy link
Copy Markdown
Member

Thank you @Yashp002

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iritkatriel
iritkatriel enabled auto-merge (squash) January 25, 2026 13:18
@Yashp002

Yashp002 commented Jan 25, 2026

Copy link
Copy Markdown
Contributor Author

@iritkatriel , @picnixz Thanks for the help

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz approved these changes Jan 25, 2026
View reviewed changes
@iritkatriel
iritkatriel merged commit a51bf70 into python:main Jan 25, 2026
83 of 87 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 25, 2026
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@Yashp002 @thunder-coding
pythongh-143504: Expose CELL status of a symbol in symtable (python#1…
f3c5bfb
…43549)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aisk aisk aisk left review comments
@iritkatriel iritkatriel iritkatriel approved these changes
@picnixz picnixz picnixz approved these changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Yashp002 @picnixz @iritkatriel @aisk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.