Repository navigation
Expose capsule type in types module #109599
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Sep 20, 2023 This came up initially in #109562
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Sep 20, 2023 What is the use case? AFAIK capsule objects are never used in the Python API. They are used in the C API, so perhaps
ctypesis a better place? Although I do not know how it can be used there too.From user's point of view the only difference of capsule type from
objectis its__repr__and__doc__. You cannot create a capsule object, you cannot use its methods or attributes, there is no Python API that returns or takes a capsule object.Not every builtin type is exposed in types module.
The use case is introspection, as with other types in the
typesmodule.Also, please take a look at the issue I mentioned above, where the context is explained in a bit more detail: #109562
How can it help in introspection? What can you do with a capsule object in Python?
The same argument can be applied to list_iterator. I am against cluttering types module.
Reacted by Alex WaygoodReacted by Alexander KarpinskyAgain, the problem I'm trying to solve is explained in the #109562 issue description.
I personally think a parametric type in thetypingmodule would be better (so that one can specificy the capsule name, such astyping.Capsule["dltensor"]), buttypes.CapsuleTypewould still be better than nothing.You don't have to understand or care about that problem, but then please don't throw around dismissive opinions such as "I'm against cluttering X". This is unhelpful and hostile.
Reacted by Damian Eads and Alexander KarpinskyI'm sorry that I was categorical. This is just my personal opinion and you are free to ignore it. But I hope that you will consider other options for solving your problem. Cluttering the types module has disadvantages.
Reacted by Antoine PitrouI would support adding this type. None and NotImplemented also have no Python-visible API to speak of, and yet we added
NoneTypeandNotImplementedTypeto thetypesmodule.Reacted by Adam Turner and Erlend E. Aasland- added a commit that references this issue
on Sep 25, 2023 It looks to me this was implemented; can we close this, @pitrou?
Yes, sorry. I always forget that merging a PR does not automatically close the associated issue.
Reacted by Erlend E. Aasland
Feature or enhancement
Proposal:
It would be nice if the type of capsule objects was exposed in the
typesmodule, just like other interpreter types.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
CapsuleTypevia the_typesmodule #131969