gh-120029: make symtable.Symbol.__repr__ correctly reflect the compiler's flags #120099
gh-120029: make symtable.Symbol.__repr__ correctly reflect the compiler's flags #120099JelleZijlstra merged 26 commits intopython:mainfrom
symtable.Symbol.__repr__ correctly reflect the compiler's flags #120099Conversation
- restore 'symtable.SCOPE_OFF' for compatibility purposes - fix `Symbol.is_comp_cell()`
|
Thank you for the review Serhiy. By the way, is it fine for me to re-request a review after addressing what you've reviewed or do you prefer not to have notifications' noise (same question for Jelle)? |
There was a problem hiding this comment.
DEF_FREE_CLASS is used in a case like this:
def f():
x = 1
class C:
x = 2
def method(self):
return x
The method() method should return 1 -- it doesn't see the class-scoped x, but it does see the function-scoped x outside the class. The class-scoped x is marked DEF_FREE_CLASS in this case, to make that work.
It's such a niche use that I don't think we are going to find a method name here that nicely represents it in an intuitive way. Best option is probably just is_free_class to match the flag name.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
Ah, I should have said "I have made the requested changes; please review again". |
|
Thanks for making the requested changes! @carljm, @serhiy-storchaka: please review the changes made to this pull request. |
Misc/NEWS.d/next/Library/2024-06-05-11-03-10.gh-issue-120029.QBsw47.rst
Outdated
Show resolved
Hide resolved
|
I think this now needs to be updated for compatibility with the merge of the PEP 649 compiler implementation. |
…e compiler's flags, add methods (python#120099) Expose :class:`symtable.Symbol` methods :meth:`~symtable.Symbol.is_free_class`, :meth:`~symtable.Symbol.is_comp_iter` and :meth:`~symtable.Symbol.is_comp_cell`. --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
…e compiler's flags, add methods (python#120099) Expose :class:`symtable.Symbol` methods :meth:`~symtable.Symbol.is_free_class`, :meth:`~symtable.Symbol.is_comp_iter` and :meth:`~symtable.Symbol.is_comp_cell`. --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
…e compiler's flags, add methods (python#120099) Expose :class:`symtable.Symbol` methods :meth:`~symtable.Symbol.is_free_class`, :meth:`~symtable.Symbol.is_comp_iter` and :meth:`~symtable.Symbol.is_comp_cell`. --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
I did not expose
is_free_classyet because I don't really know whether it's the best name or not, nor did I handle theDEF_FREEflag because I don't know its difference with theFREEscope itself (see #120029 (comment)).I've nonethless cleaned up the lambda functions used to getting the scope
and also exportedSCOPE_OFFSETinstead ofSCOPE_OFF(those constants are actually private since they are not documented so it should not affect public API). I can revert those changes easily though if you want me to make them in another PR.cc @JelleZijlstra @carljm
symtablemodule.c#120029📚 Documentation preview 📚: https://cpython-previews--120099.org.readthedocs.build/