Skip to content

make the type-parameter of ctypes.py_object optional#13760

Merged
srittau merged 1 commit into
python:mainfrom
jorenham:ctypes.py_object-generic-default
Apr 7, 2025
Merged

make the type-parameter of ctypes.py_object optional#13760
srittau merged 1 commit into
python:mainfrom
jorenham:ctypes.py_object-generic-default

Conversation

@jorenham

@jorenham jorenham commented Apr 1, 2025

Copy link
Copy Markdown
Contributor

Type-checkers currently require a generic type argument for ctypes.py_object. But at runtime this can raise a TypeError if not quoted.
We can avoid this contradictory paradox that's sending conflicting mixed signals by setting the type-parameter default of ctypes.py_object to Any.

@github-actions

This comment has been minimized.

@brianschubert

Copy link
Copy Markdown
Collaborator

But at runtime this can raise a TypeError if not quoted.

Which begs the question, should ctypes.py_object define __class_getitem__ at runtime, to mirror the stubs?

@jorenham

jorenham commented Apr 2, 2025

Copy link
Copy Markdown
Contributor Author

But at runtime this can raise a TypeError if not quoted.

Which begs the question, should ctypes.py_object define __class_getitem__ at runtime, to mirror the stubs?

Maybe? But even if that were to be changed in cpython, then that'd only fix it for 3.14+ or something. So I suppose that this would still be relevant

@brianschubert

Copy link
Copy Markdown
Collaborator

It seems that there's very few instances of generic py_object being used in the wild, most of which are from numpy/optypes. Is it being generic actually useful? I wonder if it would make sense to specialize it to Any or object

@jorenham

jorenham commented Apr 2, 2025

Copy link
Copy Markdown
Contributor Author

It seems that there's very few instances of generic py_object being used in the wild, most of which are from numpy/optypes.

Well, I admit that this is mostly self-interest, haha.

Oh and it's optype btw ;)

@jorenham

jorenham commented Apr 2, 2025

Copy link
Copy Markdown
Contributor Author

Is it being generic actually useful? I wonder if it would make sense to specialize it to Any or object

Not at the moment, no. But once mypy fully supports __new__, then I can make numpy.object_ generic. And then it would help to also have a generic ctypes.py_object.

@jorenham jorenham force-pushed the ctypes.py_object-generic-default branch from d5c4051 to f7e2270 Compare April 4, 2025 02:47
@github-actions

github-actions Bot commented Apr 4, 2025

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants