Skip to content

Typing of ctypes' pointer types is wrong #8351

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

Closed
svenpanne opened this issue Jul 21, 2022 · 4 comments · Fixed by #8446
Closed

Typing of ctypes' pointer types is wrong #8351

svenpanne opened this issue Jul 21, 2022 · 4 comments · Fixed by #8446
Assignees

Comments

@svenpanne
Copy link

https://docs.python.org/3/library/ctypes.html#pointers explicitly says:

Calling the pointer type without an argument creates a NULL pointer.

and even has a code example for this:

null_ptr = POINTER(c_int)()

But the pointer constructor

def __init__(self, arg: _CT) -> None: ...
requires an argument. This should be optional if I understand the code there correctly.

@AlexWaygood
Copy link
Member

Hum, this was probably my mistake. I changed this in #8074 due to observing this behaviour in the interactive REPL:

>>> from ctypes import pointer
>>> pointer()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: _ctypes.pointer() takes exactly one argument (0 given)

@AlexWaygood
Copy link
Member

The entire ctypes stub appears to be a lie (pointer() is given as a class, but in reality it's a function). Ideally I think we'd fix that, but that might be a breaking change. Not really sure what the best course of action is tbh.

@srittau
Copy link
Collaborator

srittau commented Jul 21, 2022

If there only was a way to judge the impact of a change. 🤔 But seriously, I would just try the changes and see whether primer explodes.

@AlexWaygood
Copy link
Member

If there only was a way to judge the impact of a change. 🤔 But seriously, I would just try the changes and see whether primer explodes.

I'll get on it.

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 a pull request may close this issue.

3 participants