Skip to content

Cannot typecheck ctypes NULL pointer instantiation #13930

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
etanol opened this issue Oct 20, 2022 · 2 comments
Closed

Cannot typecheck ctypes NULL pointer instantiation #13930

etanol opened this issue Oct 20, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@etanol
Copy link

etanol commented Oct 20, 2022

Bug Report

According to the ctypes documentation, the ctypes.POINTER factory function creates new pointer types. If those pointer types are called/instantiated without arguments, then a NULL pointer is created.

python/typeshed#8446 fixed some errors in the ctypes type definitions. But now, Mypy still fails to validate legal code creating NULL pointers.

To Reproduce

from ctypes import POINTER, c_char

charp = POINTER(c_char)
null = charp()
assert not null, "NULL is evaluating to True!"

Expected Behavior

The above snippet should successfully type check.

Actual Behavior

sample.py:4: error: Missing positional argument "arg" in call to "pointer"
    null = charp()
           ^
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.982
  • Mypy command-line flags: --pretty
  • Mypy configuration options from mypy.ini (and other config files): no customizations, no INI file created
  • Python version used: 3.10.7
@etanol etanol added the bug mypy got something wrong label Oct 20, 2022
@etanol
Copy link
Author

etanol commented Oct 20, 2022

Given how ctypes hints are defined now, I don't understand the connection Mypy makes between the _Pointer class and the pointer function. Perhaps there's an issue in the ctypes plugin?

@etanol
Copy link
Author

etanol commented Oct 20, 2022

Sorry, my mistake. Due to a bogus virtual environment, I was not using Mypy 0.982. I tried with a clean install and it works.

Resolving.

@etanol etanol closed this as completed Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant