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

pyclass: move flags to PyClassImpl #1456

Merged
merged 2 commits into from
Mar 17, 2021
Merged

Conversation

davidhewitt
Copy link
Member

This is a (mostly internal) refactoring to move some pieces of PyTypeInfo which aren't needed for anything other than #[pyclass] onto the PyClassImpl trait.

At the same time I cleaned up the old FLAGS constant which still had unneeded entries for e.g. weakref.

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Thanks!
Looks like reasonable changes, but why PyClassImpl instead of PyClass?
I understand that PyClassImpl is for collecting methods by pseudo-specialization trick, so I don't see the necessity to place these flags under PyClassImpl.

src/pyclass.rs Outdated Show resolved Hide resolved
src/pyclass.rs Outdated Show resolved Hide resolved
src/class/impl_.rs Outdated Show resolved Hide resolved
@davidhewitt
Copy link
Member Author

Looks like reasonable changes, but why PyClassImpl instead of PyClass?

Overall I see PyClassImpl as the pieces of PyClass which we don't consider stable API (it's #[doc(hidden)]). So unless we are sure this is useful for users and it's not going to need to change, it should go on PyClassImpl.

To reduce the complex trait hierarchy I was thinking to merge PyClassAlloc into PyClassImpl also.

@kngwyu
Copy link
Member

kngwyu commented Mar 4, 2021

How about moving some flags under PyClassAlloc?
They are actually related only to allocation.

@davidhewitt
Copy link
Member Author

davidhewitt commented Mar 4, 2021

How about moving some flags under PyClassAlloc? They are actually related only to allocation.

Only the IS_SUBCLASS flag is used during the default_new implementation - the others are used in py_class_flags which isn't anything to do with allocation.

I'll have a go with a follow-up commit to try refactoring PyClassAlloc a bit. 👍

@davidhewitt
Copy link
Member Author

I've pushed a commit which removes the #[inline] and puts PyTypeInfo bound onto PyClassAlloc instead of PyClassImpl. Also renamed T::DESCRIPTION to T::DOC for simplification.

I looked at doing further work to PyClassAlloc in this PR but realised there are a lot of complications with that trait as-is, especially with #991.

So I will try and push something experimental in a separate PR later.

@davidhewitt davidhewitt requested a review from kngwyu March 14, 2021 08:40
Base automatically changed from master to main March 16, 2021 22:09
Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@kngwyu kngwyu merged commit 6137e3a into PyO3:main Mar 17, 2021
@davidhewitt davidhewitt deleted the pyclass-impl-flags branch December 24, 2021 02:07
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.

2 participants