Skip to content

move and rename from ctypes._FuncPointer to _ctypes.CFuncPtr #10140

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

Merged
merged 9 commits into from
May 6, 2023

Conversation

junkmd
Copy link
Contributor

@junkmd junkmd commented May 5, 2023

@github-actions

This comment has been minimized.

@junkmd
Copy link
Contributor Author

junkmd commented May 5, 2023

Stubtests are failed.

Quoting from https://github.com/python/typeshed/actions/runs/4889040813/jobs/8727237786?pr=10140#step:5:19,

error: _ctypes.CFuncPtr cannot be subclassed at runtime, but isn't marked with @Final in the stub

However, the return value of CFUNCTYPE is a subclass of _ctypes.CFuncPtr at runtime.
https://github.com/python/cpython/blob/872cbc613245db7a1fc5e6656ed0135d2e115f50/Lib/ctypes/__init__.py#L73-L107

I wonder why it occurs.

Any opinions would be appreciated.

@JelleZijlstra
Copy link
Member

Stubtest probably just tries to do something like:

>>> class X(ctypes._CFuncPtr): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: class must define _flags_ which must be an integer

It can only be subclassed if the subclass sets fields like _flags_. I think we can simply add it to the allowlist (tests/stubtest_allowlists/py3_common.txt probably).

@github-actions

This comment has been minimized.

and remove `_ctypes.CFuncPtr._flags_` from allowlists
@junkmd junkmd force-pushed the move_FuncPointer_CFuncPtr branch from e6e78cd to caedbda Compare May 5, 2023 06:31
@github-actions

This comment has been minimized.

@junkmd
Copy link
Contributor Author

junkmd commented May 5, 2023

Both adding _ctypes.CFuncPtr._flags_ to allowlists(6399ecd) and adding the _flags_ attribute to _ctypes.CFuncPtr(caedbda) doesn't resolve this problem 😭.

@AlexWaygood
Copy link
Member

AlexWaygood commented May 5, 2023

Both adding _ctypes.CFuncPtr._flags_ to allowlists(6399ecd) and adding the _flags_ attribute to _ctypes.CFuncPtr(caedbda) doesn't resolve this problem 😭.

You needed to add _ctypes.CFuncPtr to the allowlist rather than _ctypes.CFuncPtr._flags_ — I've corrected it for you :)

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood requested a review from JelleZijlstra May 5, 2023 07:00
@junkmd
Copy link
Contributor Author

junkmd commented May 5, 2023

@AlexWaygood
Thank you for the correction.

@github-actions
Copy link
Contributor

github-actions bot commented May 5, 2023

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

@JelleZijlstra JelleZijlstra merged commit a6ecf56 into python:main May 6, 2023
@junkmd junkmd deleted the move_FuncPointer_CFuncPtr branch May 6, 2023 23:01
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