bpo-42035: Add a PyType_GetQualName() to get type's qualified name.#27551
bpo-42035: Add a PyType_GetQualName() to get type's qualified name.#27551encukou merged 2 commits intopython:mainfrom
Conversation
|
@encukou Hi, Petr. Would you mind to take a look :) |
| if (PyObject_SetAttrString(HeapTypeNameType, | ||
| "__qualname__", spec_name) < 0) { |
There was a problem hiding this comment.
This is an interesting test.
Would it make sense to test the original qualname first, then assign a different one and test that PyType_GetQualName returns the replacement?
There was a problem hiding this comment.
Haha. I try to get some qual names in _testcapimodule. But I can get the qual name with prefix.
The reason is res->ht_qualname = res->ht_name; in https://github.com/python/cpython/blob/main/Objects/typeobject.c#L3439.
I don't know the reason why the qual name need to reomve the prefix too.
So I set a qual name with prefix to test this C API, somthing like a mock behavior~
There was a problem hiding this comment.
Right, C-API classes don't have distinct qualnames.
IMO, the best thing to do here would be:
- Test the original qualname (same as the short name)
- Change the qualname
- Then test the new qualname.
Ideally, the same thing would be tested for PyType_GetName as well – it's not that different from this function.
There was a problem hiding this comment.
Right, C-API classes don't have distinct qualnames.
IMO, the best thing to do here would be:
- Test the original qualname (same as the short name)
- Change the qualname
- Then test the new qualname.
Make sense. How about this updated PR :)
Ideally, the same thing would be tested for
PyType_GetNameas well – it's not that different from this function.
Got it. I will update enhance this test case later.
|
Looks good, thanks! |
Thanks a million, petr :) |
https://bugs.python.org/issue42035