Skip to content

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

Merged
jameslamb merged 1 commit into
masterfrom
mypy/ctypes-arrays
Nov 22, 2023
Merged

jameslamb merged 1 commit into
masterfrom
mypy/ctypes-arrays

Conversation

@jameslamb

Copy link
Copy Markdown
Member

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
@jameslamb
jameslamb deleted the mypy/ctypes-arrays branch November 22, 2023 18:36
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants