Skip to content

Conversation

Tpt
Copy link
Contributor

@Tpt Tpt commented Aug 18, 2025

Introduces PyClassBaseType::BASE_NAME to store the module name + class name of the base type

@@ -184,15 +184,16 @@ macro_rules! pyobject_native_type_core {
#[doc(hidden)]
#[macro_export]
macro_rules! pyobject_subclassable_native_type {
($name:ty, $layout:path $(;$generics:ident)*) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The generics field was unused

Copy link
Member

Choose a reason for hiding this comment

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

I think it might be used downstream in rust-numpy, where $name may be a generic type 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not see an occurence of pyobject_subclassable_native_type! in Rust numpy (the macro it uses is pyobject_native_type_named) and the only other macro calling it in PyO3 is impl_native_exception! that does not allow generics. But happy to revert the change if you prefer.

Copy link
Member

@davidhewitt davidhewitt Aug 22, 2025

Choose a reason for hiding this comment

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

Given that all of the macros currently have the same generics syntax, I think it would be better to keep this as-is, yes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: 7433225

@Tpt Tpt force-pushed the tpt/introspection-extends branch 2 times, most recently from 3f497da to 0a01104 Compare August 18, 2025 07:06
@@ -1139,6 +1139,8 @@ pub trait PyClassBaseType: Sized {
type BaseNativeType;
type Initializer: PyObjectInit<Self>;
type PyClassMutability: PyClassMutability;
/// Fully qualified name of the base class including modules
const BASE_NAME: &'static str;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not gated this associated constants with the experimental-inspect feature because it's an internal trait often generated using macro_rules!.

I have not reused IntoPyObject::OUTPUT_TYPE because they might be different (typing.Any vs object...)

Happy to rename the constant to something better.

Copy link
Member

Choose a reason for hiding this comment

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

Is this information suitable to get from PyTypeInfo (which has name + module) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. I would need to fix the NAME for a lot of types. Currently it's setup by the macro to be the same as the Rust type name. So, for example, <PyDict as PyTypeInfo>::NAME == "PyDict" and not dict. Happy to do it if you want.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, that's a good point. I think that's probably just a historical mistake, it also leads to a lot of sad error messages where we leak the PyDict name out to consumers downstream that probably don't need to know about PyO3.

I think doing that as a precursor PR might be desirable? I can try to do so later, perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Thanks! It will actually be also useful to generate some type stubs. I hope to be able to do it today, feel free to focus on something else.

@Tpt Tpt force-pushed the tpt/introspection-extends branch 3 times, most recently from ae15fd0 to 057bfa1 Compare August 18, 2025 08:35
@Tpt Tpt force-pushed the tpt/introspection-extends branch from 057bfa1 to e5d3ee2 Compare August 18, 2025 08:51
Introduces PyClassBaseType::BASE_NAME to store the module name + class name of the base type
@Tpt Tpt force-pushed the tpt/introspection-extends branch from e5d3ee2 to fb793af Compare August 18, 2025 09:01
@@ -1139,6 +1139,8 @@ pub trait PyClassBaseType: Sized {
type BaseNativeType;
type Initializer: PyObjectInit<Self>;
type PyClassMutability: PyClassMutability;
/// Fully qualified name of the base class including modules
const BASE_NAME: &'static str;
Copy link
Member

Choose a reason for hiding this comment

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

Is this information suitable to get from PyTypeInfo (which has name + module) ?

@@ -184,15 +184,16 @@ macro_rules! pyobject_native_type_core {
#[doc(hidden)]
#[macro_export]
macro_rules! pyobject_subclassable_native_type {
($name:ty, $layout:path $(;$generics:ident)*) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be used downstream in rust-numpy, where $name may be a generic type 👀

@davidhewitt
Copy link
Member

I think this is blocked on #5352 ? Setting to draft for the moment.

@davidhewitt davidhewitt marked this pull request as draft September 14, 2025 12:26
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