From 6b55150e80958f1de4719088726541b7256fe7ef Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 2 Jun 2022 18:04:46 +0800 Subject: [PATCH] Fix pylint errors. (#7967) --- python-package/setup.py | 2 +- python-package/xgboost/callback.py | 2 +- python-package/xgboost/core.py | 15 ++++++++------- python-package/xgboost/dask.py | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/python-package/setup.py b/python-package/setup.py index 6c83feca0..b4f05e027 100644 --- a/python-package/setup.py +++ b/python-package/setup.py @@ -96,7 +96,7 @@ class BuildExt(build_ext.build_ext): # pylint: disable=too-many-ancestors logger = logging.getLogger('XGBoost build_ext') - # pylint: disable=too-many-arguments,no-self-use + # pylint: disable=too-many-arguments def build( self, src_dir: str, diff --git a/python-package/xgboost/callback.py b/python-package/xgboost/callback.py index 021ccd972..102d53ce4 100644 --- a/python-package/xgboost/callback.py +++ b/python-package/xgboost/callback.py @@ -1,5 +1,5 @@ # coding: utf-8 -# pylint: disable=invalid-name, too-many-statements, no-self-use +# pylint: disable=invalid-name, too-many-statements # pylint: disable=too-many-arguments """Callback library containing training routines. See :doc:`Callback Functions ` for a quick introduction. diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 6ec1fbf45..acab3ee52 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -3,6 +3,7 @@ """Core XGBoost Library.""" from abc import ABC, abstractmethod from collections.abc import Mapping +import copy from typing import List, Optional, Any, Union, Dict, TypeVar from typing import Callable, Tuple, cast, Sequence, Type, Iterable import ctypes @@ -1638,7 +1639,7 @@ class Booster: booster: `Booster` a copied booster model """ - return self.__copy__() + return copy.copy(self) def attr(self, key: str) -> Optional[str]: """Get attribute string from the Booster. @@ -2370,15 +2371,15 @@ class Booster: ret = self.get_dump(fmap, with_stats, dump_format) if dump_format == 'json': fout_obj.write('[\n') - for i, _ in enumerate(ret): - fout_obj.write(ret[i]) + for i, val in enumerate(ret): + fout_obj.write(val) if i < len(ret) - 1: fout_obj.write(",\n") fout_obj.write('\n]') else: - for i, _ in enumerate(ret): + for i, val in enumerate(ret): fout_obj.write(f"booster[{i}]:\n") - fout_obj.write(ret[i]) + fout_obj.write(val) if need_close: fout_obj.close() @@ -2667,8 +2668,8 @@ class Booster: values = [] # pylint: disable=consider-using-f-string regexp = re.compile(r"\[{0}<([\d.Ee+-]+)\]".format(feature)) - for i, _ in enumerate(xgdump): - m = re.findall(regexp, xgdump[i]) + for i, val in enumerate(xgdump): + m = re.findall(regexp, val) values.extend([float(x) for x in m]) n_unique = len(np.unique(values)) diff --git a/python-package/xgboost/dask.py b/python-package/xgboost/dask.py index 4363feac7..f9176c023 100644 --- a/python-package/xgboost/dask.py +++ b/python-package/xgboost/dask.py @@ -1719,7 +1719,7 @@ class DaskScikitLearnBase(XGBModel): """Implementation of the Scikit-Learn API for XGBoost.""", ["estimators", "model"] ) class DaskXGBRegressor(DaskScikitLearnBase, XGBRegressorBase): - # pylint: disable=missing-class-docstring + """dummy doc string to workaround pylint, replaced by the decorator.""" async def _fit_async( self, X: _DaskCollection,