Skip to content

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

Merged
JelleZijlstra merged 9 commits into
python:mainfrom
junkmd:move_FuncPointer_CFuncPtr
May 6, 2023
Merged

JelleZijlstra merged 9 commits into
python:mainfrom
junkmd:move_FuncPointer_CFuncPtr

Conversation

@junkmd

@junkmd junkmd commented May 5, 2023

Copy link
Copy Markdown
Contributor

@github-actions

This comment has been minimized.

@junkmd

junkmd commented May 5, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

junkmd commented May 5, 2023

Copy link
Copy Markdown
Contributor Author

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

@AlexWaygood

AlexWaygood commented May 5, 2023 •

Copy link
Copy Markdown
Member

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

junkmd commented May 5, 2023

Copy link
Copy Markdown
Contributor Author

@AlexWaygood
Thank you for the correction.

@github-actions

github-actions Bot commented May 5, 2023

Copy link
Copy Markdown
Contributor

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