Skip to content

gh-120029: make symtable.Symbol.__repr__ correctly reflect the compiler's flags #120099

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

Merged
merged 26 commits into from
Jun 12, 2024

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Jun 5, 2024

I did not expose is_free_class yet because I don't really know whether it's the best name or not, nor did I handle the DEF_FREE flag because I don't know its difference with the FREE scope itself (see #120029 (comment)).

I've nonethless cleaned up the lambda functions used to getting the scope and also exported SCOPE_OFFSET instead of SCOPE_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


📚 Documentation preview 📚: https://cpython-previews--120099.org.readthedocs.build/

- restore 'symtable.SCOPE_OFF' for compatibility purposes
- fix `Symbol.is_comp_cell()`
@picnixz
Copy link
Member Author

picnixz commented Jun 6, 2024

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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bedevere-app
Copy link

bedevere-app bot commented Jun 6, 2024

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz picnixz requested a review from carljm June 7, 2024 07:27
@picnixz
Copy link
Member Author

picnixz commented Jun 7, 2024

Ah, I should have said "I have made the requested changes; please review again".

@bedevere-app
Copy link

bedevere-app bot commented Jun 7, 2024

Thanks for making the requested changes!

@carljm, @serhiy-storchaka: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from serhiy-storchaka June 7, 2024 08:11
@carljm carljm enabled auto-merge (squash) June 11, 2024 14:49
@carljm carljm disabled auto-merge June 11, 2024 15:17
@carljm
Copy link
Member

carljm commented Jun 11, 2024

I think this now needs to be updated for compatibility with the merge of the PEP 649 compiler implementation.

@JelleZijlstra JelleZijlstra merged commit 755dab7 into python:main Jun 12, 2024
36 checks passed
@picnixz picnixz deleted the export-symtable-flags branch June 12, 2024 11:17
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
…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 <[email protected]>
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
…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 <[email protected]>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
…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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants