Skip to content
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

__static_attributes__ doesn't include method calls #122445

Closed
PierreQuentel opened this issue Jul 30, 2024 · 4 comments · Fixed by #122446
Closed

__static_attributes__ doesn't include method calls #122445

PierreQuentel opened this issue Jul 30, 2024 · 4 comments · Fixed by #122446
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@PierreQuentel
Copy link
Contributor

PierreQuentel commented Jul 30, 2024

Feature or enhancement

Proposal:

class C:

  def f(self):
    self.x
    self.y[3]
    self.z()

print(C.__static_attributes__) # gives ('y', 'x'), but 'z' is absent

From 3.13 documentation, __static_attributes__ is A tuple containing names of attributes of this class which are accessed through self.X from any function in its body.`. Is there a reason why subscriptions are included in the result, but not method calls ?

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@PierreQuentel PierreQuentel added the type-feature A feature request or enhancement label Jul 30, 2024
@Eclips4 Eclips4 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 30, 2024
@Eclips4
Copy link
Member

Eclips4 commented Jul 30, 2024

cc @iritkatriel

@markshannon
Copy link
Member

__static_attributes__ is supposed to be a static approximation of the instance attributes, not the class's attributes.
So including methods is counter productive.

Maybe probably should only be counting stores, not loads when filling __static_attributes__?

@iritkatriel
Copy link
Member

__static_attributes__ is supposed to be a static approximation of the instance attributes, not the class's attributes. So including methods is counter productive.

Maybe probably should only be counting stores, not loads when filling __static_attributes__?

I was thinking the same, but then we need to change the documentation as well to make this clear.

@PierreQuentel
Copy link
Contributor Author

Thank you Irit and Mark !

iritkatriel added a commit to iritkatriel/cpython that referenced this issue Aug 2, 2024
iritkatriel added a commit that referenced this issue Aug 2, 2024
…s__ (#122446) (#122621)

gh-122445: populate only modified fields in __static_attributes__ (#122446)

(cherry picked from commit 498376d)
brandtbucher pushed a commit to brandtbucher/cpython that referenced this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants