Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose capsule type in types module #109599

Closed
pitrou opened this issue Sep 20, 2023 · 9 comments
Closed

Expose capsule type in types module #109599

pitrou opened this issue Sep 20, 2023 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Sep 20, 2023

Feature or enhancement

Proposal:

It would be nice if the type of capsule objects was exposed in the types module, 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

@pitrou pitrou added the type-feature A feature request or enhancement label Sep 20, 2023
@pitrou
Copy link
Member Author

pitrou commented Sep 20, 2023

This came up initially in #109562

@pitrou pitrou added the stdlib Python modules in the Lib dir label Sep 20, 2023
@pitrou pitrou self-assigned this Sep 20, 2023
@serhiy-storchaka
Copy link
Member

What is the use case? AFAIK capsule objects are never used in the Python API. They are used in the C API, so perhaps ctypes is 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 object is 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.

@pitrou
Copy link
Member Author

pitrou commented Sep 20, 2023

The use case is introspection, as with other types in the types module.

Also, please take a look at the issue I mentioned above, where the context is explained in a bit more detail: #109562

@serhiy-storchaka
Copy link
Member

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.

@pitrou
Copy link
Member Author

pitrou commented Sep 20, 2023

Again, the problem I'm trying to solve is explained in the #109562 issue description.
I personally think a parametric type in the typing module would be better (so that one can specificy the capsule name, such as typing.Capsule["dltensor"]), but types.CapsuleType would 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.

@serhiy-storchaka
Copy link
Member

I'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.

@JelleZijlstra
Copy link
Member

I would support adding this type. None and NotImplemented also have no Python-visible API to speak of, and yet we added NoneType and NotImplementedType to the types module.

pitrou added a commit that referenced this issue Sep 25, 2023
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
csm10495 pushed a commit to csm10495/cpython that referenced this issue Sep 28, 2023
---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
@erlend-aasland
Copy link
Contributor

It looks to me this was implemented; can we close this, @pitrou?

@pitrou
Copy link
Member Author

pitrou commented Oct 5, 2023

Yes, sorry. I always forget that merging a PR does not automatically close the associated issue.

@pitrou pitrou closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants