Skip to content

Implements basic method introspection #5087

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 3 commits into from
May 14, 2025
Merged

Implements basic method introspection #5087

merged 3 commits into from
May 14, 2025

Conversation

Tpt
Copy link
Contributor

@Tpt Tpt commented Apr 23, 2025

Implementation notes:

  • I am not sure about the decorators for class attributes. I am using the @classmethod\n@property combination that got removed in Python 3.11. I don't see a clean way to do it in the next Python versions. It's possible that type checkers work properly with it, we will need to check but I would prefer to focus on other things for now.
  • When we introspect the class definition (#[pyclass] macro) we don't know the list of method so each method is generating its own introspection fragment with a "parent" attribute that connects a method to its class. We will likely reuse it again for nested classes used in complex enums.
  • We are generating a / after the self or cls argument even (if they are not other positional-only arguments). It's not nice but syntactically correct.
  • I have not tested all magic methods

@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label Apr 23, 2025
@bschoenmaeckers
Copy link
Member

I am not sure about the decorators for class attributes. I am using the @classmethod\n@property combination that got removed in Python 3.11. I don't see a clean way to do it in the next Python versions. It's possible that type checkers work properly with it, we will need to check but I would prefer to focus on other things for now.

Should we run a type-checker in the CI to verify the generated types?

@Tpt
Copy link
Contributor Author

Tpt commented Apr 23, 2025

Should we run a type-checker in the CI to verify the generated types?

Yes, I am planning to do it when the implementation will be a bit more feature complete. At this stage it will complain a lot about missing elements in the stubs.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me. Same as #5025, sorry I have been a bit slow here. I have just a few comments.

I am not sure about the decorators for class attributes.

I suspect the solution lies in either typing.Final or typing.ClassVar.

@davidhewitt
Copy link
Member

Let's send this to merge, I guess it might conflict with #5089 👍

I lost track, do we have an issue listing all the future refinements to the introspection code? It would be helpful to record all the pieces which might be improved, both soon and once Rust supports them.

@davidhewitt davidhewitt enabled auto-merge May 13, 2025 12:07
@Tpt
Copy link
Contributor Author

Tpt commented May 13, 2025

Let's send this to merge, I guess it might conflict with #5089 👍

Thank you! Yes! It will conflict.

I lost track, do we have an issue listing all the future refinements to the introspection code? It would be helpful to record all the pieces which might be improved, both soon and once Rust supports them.

Not yet, I am going to do it

@davidhewitt davidhewitt added this pull request to the merge queue May 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch May 13, 2025
@Tpt
Copy link
Contributor Author

Tpt commented May 13, 2025

Done: #5137

@Tpt
Copy link
Contributor Author

Tpt commented May 13, 2025

@davidhewitt I have pushed a fix for the CI in this branch. The branches are conflicting, what about merging this one first and the next one after I do a rebase?

@davidhewitt davidhewitt added this pull request to the merge queue May 14, 2025
Merged via the queue into PyO3:main with commit 0e298e5 May 14, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants