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

move downcast functions from PyAnyMethods to Bound<T> #3988

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidhewitt
Copy link
Member

Closes #3980

There's quite a few cases of churn where moving these methods removed the need to use PyAnyMethods around the codebase.

Possibly a less aggressive form of this would be to leave the existing implementations on PyAnyMethods and just make these new methods forward to PyAnyMethods. I'm not sure there's a good reason to duplicate the API, though, so this seems a bit cleaner.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Mar 23, 2024
@@ -96,6 +96,221 @@ where
}
}

impl<'py, T> Bound<'py, T> {
/// Downcast this `PyAny` to a concrete Python type or pyclass.
Copy link
Member

Choose a reason for hiding this comment

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

The wording seems incorrect now that the receiver is Bound<T> instead of &PyAny or even Bound<PyAny>?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe "Downcast this Python value to a subtype"?

Copy link
Member Author

Choose a reason for hiding this comment

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

As a second thought, it's not just about "downcasting" any more, as U might be a supertype of T. Would it be better to call these APIs .cast() instead of .downcast()?

(That would be a solution to avoid needing to remove the PyAnyMethods.)

I quite like .cast() though that might be a good reason to also leave this API until 0.22 and make it a more deliberate & documented addition.

@davidhewitt davidhewitt added this to the 0.22 milestone Mar 31, 2024
@davidhewitt davidhewitt modified the milestones: 0.22, 0.24 Oct 4, 2024
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.

Move PyAnyMethods::downcast to Bound smart pointer?
2 participants