pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

fix: make PyType::name consistent with __name__ and add PyType::module

Open wyfo opened this issue 10 months ago • 7 comments

fixes #4055

wyfo avatar Apr 07 '24 11:04 wyfo

I am not particularly keen on the additional complexity and would be prefer to limit to fixing inconsistencies between builds with and without abi3.

adamreichold avatar Apr 07 '24 13:04 adamreichold

As well as efficiency, it looks like PEP 737 makes it clear that exposing tp_name is a bad idea. Even though we just changed the way these worked in 0.21, I think it's probably correct to change PyType::name to just match __name__ in 0.22. Sigh.

However I agree with the complexity concern here.

Given that PEP 737 adds a new PyType_GetFullyQualifiedName function to Python 3.13, I suggest what we should do is not have PyType::full_name at all, and instead add PyType::fully_qualified_name which will be __module__.__qualname__ as per PEP 737. We can even use the API function on new Python versions.

That way we have a set of functions which match Python well, and should be relatively simple to implement:

  • PyType::name for __name__
  • PyType::qualname for __qualname__
  • PyType::module for __module__
  • PyType::fully_qualified_name for __module__.__qualname (as per PEP 737 rules of when to skip __module__).

What do you both think of this?

davidhewitt avatar Apr 11 '24 22:04 davidhewitt

I prefer to be aligned with Python dunder attributes, I find this more intuitive.

wyfo avatar Apr 12 '24 07:04 wyfo

@adamreichold as you already raised a complexity concern, what do you think of what I suggest above?

davidhewitt avatar Apr 14 '24 20:04 davidhewitt

Ping @adamreichold (and other maintainers), what do you think of this? I still believe we errored in the design for 0.21 and this correction is worthwhile despite the churn.

davidhewitt avatar May 06 '24 07:05 davidhewitt

Ping @adamreichold (and other maintainers), what do you think of this? I still believe we errored in the design for 0.21 and this correction is worthwhile despite the churn.

Yes, I agree that PEP compliance is preferable and outweighs the perceived performance benefits of borrowing tp_name. I just did not find the spare time to look into the implementation yet. Sorry for that.

adamreichold avatar May 06 '24 08:05 adamreichold

No problem, I am happy to also try to implement (or maybe @wyfo is willing to rework this PR). Mostly just wanted to make sure the design blocker was removed!

davidhewitt avatar May 06 '24 08:05 davidhewitt

Superseded by #4196. I will close this one.

davidhewitt avatar May 21 '24 12:05 davidhewitt