From c5677a2b2c692b60d4199a6814911beecd572385 Mon Sep 17 00:00:00 2001 From: michael-gendy-mention-me <107543707+michael-gendy-mention-me@users.noreply.github.com> Date: Sat, 27 May 2023 00:48:28 +0100 Subject: [PATCH] Remove `type: ignore` hints (#9197) --- python-package/xgboost/core.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 3a27f5e18..200490d73 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -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