PEP 737: gh-111696: Add type.__fully_qualified_name__ attribute#112133
PEP 737: gh-111696: Add type.__fully_qualified_name__ attribute#112133vstinner wants to merge 8 commits into
Conversation
498a4d6 to
f9a8c31
Compare
November 15, 2023 22:44
|
Existing logic to format a type name as I found a lot of code like:
stype = self.exc_type.__qualname__
smod = self.exc_type.__module__
if smod not in ("__main__", "builtins"):
if not isinstance(smod, str):
smod = "<unknown>"
stype = smod + '.' + stype
def _type_repr(obj):
...
if isinstance(obj, type):
if obj.__module__ == 'builtins':
return obj.__qualname__
return f'{obj.__module__}.{obj.__qualname__}'
...
def strclass(cls):
return "%s.%s" % (cls.__module__, cls.__qualname__) |
Sorry, something went wrong.
|
I added a second commit using the new |
Sorry, something went wrong.
Add PyType_GetFullyQualifiedName() function with documentation and tests.
19c3bf6 to
82dd956
Compare
November 16, 2023 04:35
|
Naming is hard. Taking care of myself is harder. I have a lot going on at the moment and I really would prefer not to be responsible for this particular naming decision. Hopefully one or more of the other reviewers can help instead. |
Sorry, something went wrong.
|
IMO, this should use something more customizable than an attribute. A |
Sorry, something went wrong.
malemburg
left a comment
There was a problem hiding this comment.
Functional changes should not go into this PR.
Sorry, something went wrong.
He he, I totally get it and it's perfectly fine. Take care. |
Sorry, something went wrong.
This change is not exclusive with extending unittest example from this PR:
is replaced with:
I like the ability to get an attribute rather than having to build a f-string for that. Adding new formats to format a type name in Python has been discussed in length. Most recent to oldest discussions:
Problems:
So my plan is now to add |
Sorry, something went wrong.
Yes. Did any of those discussions reach consensus on adding |
Sorry, something went wrong.
|
@JelleZijlstra: Please review the updated PR. I tried to address all comments of your latest review. |
Sorry, something went wrong.
|
I wrote PEP 737 – Unify type name formatting for these changes: see the PEP discussion. |
Sorry, something went wrong.
Thanks for taking the time to write a PEP. I think it's important that changes to builtin classes like this go through the PEP process :-) |
Sorry, something went wrong.
|
PEP 737 changed the API since this PR was created. I close this PR for now and will create a new one (or maybe reopen this PR) since PEP 737 will be approved. |
Sorry, something went wrong.
|
The Steering Council rejected the |
Sorry, something went wrong.
Add PyType_GetFullyQualName() function with documentation and tests.
📚 Documentation preview 📚: https://cpython-previews--112133.org.readthedocs.build/