Remove type: ignore hints (#9197)

This commit is contained in:
michael-gendy-mention-me 2023-05-27 00:48:28 +01:00 committed by GitHub
parent 053aababd4
commit c5677a2b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,9 +82,10 @@ def from_pystr_to_cstr(data: Union[str, List[str]]) -> Union[bytes, ctypes.Array
if isinstance(data, str):
return bytes(data, "utf-8")
if isinstance(data, list):
pointers: ctypes.Array[ctypes.c_char_p] = (ctypes.c_char_p * len(data))()
data_as_bytes = [bytes(d, "utf-8") for d in data]
pointers[:] = data_as_bytes # type: ignore
data_as_bytes: List[bytes] = [bytes(d, "utf-8") for d in data]
pointers: ctypes.Array[ctypes.c_char_p] = (
ctypes.c_char_p * len(data_as_bytes)
)(*data_as_bytes)
return pointers
raise TypeError()
@ -319,7 +320,7 @@ def _cuda_array_interface(data: DataType) -> bytes:
def ctypes2numpy(cptr: CNumericPtr, length: int, dtype: Type[np.number]) -> np.ndarray:
"""Convert a ctypes pointer array to a numpy array."""
ctype: Type[CNumeric] = _numpy2ctypes_type(dtype)
if not isinstance(cptr, ctypes.POINTER(ctype)): # type: ignore
if not isinstance(cptr, ctypes.POINTER(ctype)):
raise RuntimeError(f"expected {ctype} pointer")
res = np.zeros(length, dtype=dtype)
if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
@ -2460,9 +2461,9 @@ class Booster:
raise TypeError("Unknown file type: ", fname)
if self.attr("best_iteration") is not None:
self.best_iteration = int(self.attr("best_iteration")) # type: ignore
self.best_iteration = int(cast(int, self.attr("best_iteration")))
if self.attr("best_score") is not None:
self.best_score = float(self.attr("best_score")) # type: ignore
self.best_score = float(cast(float, self.attr("best_score")))
def num_boosted_rounds(self) -> int:
"""Get number of boosted rounds. For gblinear this is reset to 0 after