Skip to content
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

[python-package] ignore mypy errors related to ctypes string buffers #6198

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

jameslamb
Copy link
Collaborator

Contributes to #3867.

A few places in the Python package pre-allocate C char arrays with ctypes.create_string_buffer(), then pass a C array of pointers to those buffers through LightGBM's C API.

mypy is not happy about the way that's done:

python-package/lightgbm/basic.py:2951: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]
python-package/lightgbm/basic.py:2965: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]
python-package/lightgbm/basic.py:4631: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]
python-package/lightgbm/basic.py:4645: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]
python-package/lightgbm/basic.py:4855: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]
python-package/lightgbm/basic.py:4871: error: Array constructor argument 1 of type "map[int]" is not convertible to the array element type "Iterable[c_char_p]"  [misc]

The way the package does this appears to follow all of the guidance from ctypes in https://docs.python.org/3/library/ctypes.html#arrays, so I suspect this might be an issue with the ctypes type hints or maybe mypy's type inference. I reported that at python/mypy#6212 (comment).

This PR proposes just ignoring those issues with #type: ignore comments.

@jameslamb jameslamb merged commit d9a4cf4 into master Nov 22, 2023
41 checks passed
@jameslamb jameslamb deleted the mypy/ctypes-arrays branch November 22, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants