diff --git a/python-package/lightgbm/basic.py b/python-package/lightgbm/basic.py index b3f0b2e805ac..bdda0f03a565 100644 --- a/python-package/lightgbm/basic.py +++ b/python-package/lightgbm/basic.py @@ -10,7 +10,7 @@ from functools import wraps from logging import Logger from tempfile import NamedTemporaryFile -from typing import Any, Dict, Iterable, List, Set, Union +from typing import Any, Dict, Iterable, List, Set, Union, Tuple import numpy as np import scipy.sparse @@ -640,7 +640,7 @@ def is_class(obj): return hasattr(obj, "__getitem__") and hasattr(obj, "__len__") @abc.abstractmethod - def __getitem__(self, idx): # type: (Union[int, slice]) -> np.ndarray + def __getitem__(self, idx: Union[int, slice]) -> np.ndarray: """Return data for given row index. A basic implementation should look like this: @@ -667,7 +667,7 @@ def __getitem__(self, idx): # type: (Union[int, slice]) -> np.ndarray raise NotImplementedError("remove this line if subclassing") @abc.abstractmethod - def __len__(self): # type: () -> int + def __len__(self) -> int: """Return row count of this sequence.""" raise NotImplementedError @@ -1492,8 +1492,7 @@ def _lazy_init(self, data, label=None, reference=None, # set feature names return self.set_feature_name(feature_name) - def __yield_row_from(self, seqs, indices): - # type: (List[Sequence], Iterable[int]) -> ... + def __yield_row_from(self, seqs: List[Sequence], indices: Iterable[int]): offset = 0 seq_id = 0 seq = seqs[seq_id] @@ -1507,8 +1506,7 @@ def __yield_row_from(self, seqs, indices): row = seq[int(id_in_seq)] yield row if row.flags['OWNDATA'] else row.copy() - def __sample(self, seqs, total_nrow): - # type: (List[Sequence], int, int) -> (np.ndarray, List[np.ndarray]) + def __sample(self, seqs: List[Sequence], total_nrow: int) -> Tuple[np.ndarray, List[np.ndarray]]: """Sample data from seqs. Mimics behavior in c_api.cpp:LGBM_DatasetCreateFromMats() @@ -1537,8 +1535,7 @@ def __sample(self, seqs, total_nrow): return filtered, filtered_idx - def __init_from_seqs(self, seqs, params_str, ref_dataset): - # type: (List[Sequence], str, Dataset) -> None + def __init_from_seqs(self, seqs: List[Sequence], params_str: str, ref_dataset: 'Dataset'): """ Initialize data from a Sequence object.