Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-package] fix mypy errors about missing annotations and incompatible types #5672

Merged
merged 14 commits into from
Mar 9, 2023
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions python-package/lightgbm/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
_EvalResultDict = Dict[str, Dict[str, List[Any]]]
_EvalResultTuple = Union[
List[_LGBM_BoosterEvalMethodResultType],
List[Tuple[str, str, float, bool, float]]
List[Tuple[str, str, float, bool, float]],
None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't include None in this type hint. That makes it difficult to use in other parts of the code where None isn't a valid value.

]


Expand Down Expand Up @@ -51,6 +52,8 @@ def __init__(self, best_iteration: int, best_score: _EvalResultTuple) -> None:

def _format_eval_result(value: _EvalResultTuple, show_stdv: bool = True) -> str:
"""Format metric string."""
if value is None:
raise ValueError("Wrong metric value")
if len(value) == 4:
return f"{value[0]}'s {value[1]}: {value[2]:g}"
elif len(value) == 5:
Expand Down Expand Up @@ -254,10 +257,10 @@ def __init__(
self._reset_storages()

def _reset_storages(self) -> None:
self.best_score = []
self.best_iter = []
self.best_score_list = []
self.cmp_op = []
self.best_score: List[float] = []
self.best_iter: List[int] = []
self.best_score_list: List[_EvalResultTuple] = []
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
self.cmp_op: List[Callable[[float, float], bool]] = []
self.first_metric = ''

def _gt_delta(self, curr_score: float, best_score: float, delta: float) -> bool:
Expand Down