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

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.

Sign up for GitHub

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

Merged
iritkatriel merged 27 commits into python:main from Yashp002:symtable
Jan 25, 2026

Uh oh!

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

Merged

gh-143504: Expose CELL status of a symbol in symtable #143549

Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b840e4e
symtable commit
Yashp002 Jan 8, 2026
0b676e4
symtable fix 1
Yashp002 Jan 8, 2026
2175829
symtable fix 2- news
Yashp002 Jan 8, 2026
17072bd
symtable fix 3
Yashp002 Jan 21, 2026
f096488
symtable fix 4
Yashp002 Jan 21, 2026
57b36be
symtable fix 5
Yashp002 Jan 21, 2026
5c558f4
symtable fix 5
Yashp002 Jan 21, 2026
19cd54d
Merge branch 'main' into symtable
Yashp002 Jan 21, 2026
a9e5bf7
symtable fix 6
Yashp002 Jan 22, 2026
f437b13
symtable fix 6
Yashp002 Jan 23, 2026
54c8de1
symtable fix 7
Yashp002 Jan 24, 2026
3732812
symtable fix 8
Yashp002 Jan 24, 2026
d36cd84
symtable fix 8
Yashp002 Jan 24, 2026
a1ebb69
symtable fix 9
Yashp002 Jan 24, 2026
611d4d3
symtable fix 9
Yashp002 Jan 24, 2026
700a24f
symtable fix 10
Yashp002 Jan 24, 2026
2b96cb5
symtable fix 10
Yashp002 Jan 24, 2026
8c3a597
symtable fix
Yashp002 Jan 24, 2026
b36df01
Update Doc/whatsnew/3.15.rst
Yashp002 Jan 24, 2026
2539357
symtable fix 11
Yashp002 Jan 24, 2026
b8df659
symtable fix 11
Yashp002 Jan 24, 2026
68653ee
Update Doc/library/symtable.rst
Yashp002 Jan 25, 2026
6a6da41
symtable fix 12
Yashp002 Jan 25, 2026
b5e8482
symtable fix 12
Yashp002 Jan 25, 2026
14a6c28
Update Lib/symtable.py
Yashp002 Jan 25, 2026
a8bb25a
Update Doc/library/symtable.rst
Yashp002 Jan 25, 2026
43b3cfc
Merge branch 'main' into symtable
iritkatriel Jan 25, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

8 changes: 8 additions & 0 deletions 8 Lib/symtable.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ 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."""
return [s.get_name() for s in self.get_symbols() if s.is_cell()]
Comment thread Outdated

@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

Comment thread
Yashp002 marked this conversation as resolved.
Resolved

Uh oh!

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


class Class(SymbolTable):

Expand Down Expand Up @@ -342,6 +346,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."""
Expand Down
14 changes: 14 additions & 0 deletions 14 Lib/test/test_symtable.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ def test_local(self):
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"""
Comment thread Outdated

@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

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

Comment thread Outdated

@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
Comment thread
Yashp002 marked this conversation as resolved.
Resolved

Uh oh!

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

def test_referenced(self):
self.assertTrue(self.internal.lookup("x").is_referenced())
self.assertTrue(self.spam.lookup("internal").is_referenced())
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Core_and_Builtins/2026-01-08-16-28-03.gh-issue-143504.PlC_Yv.rst
Show comments
View file
Open in desktop
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.
Comment thread Outdated

@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
Loading
Oops, something went wrong.

Uh oh!

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

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.