[python-package] add type hints on Booster eval methods #5433
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to #3756 and #3867.
Adds type hints on the following closely-related methods.
Booster.eval()
Booster.eval_train()
Booster.eval_valid()
Booster.__inner_eval()
Modifies docstrings for those methods to be a bit more informative about the structure of the returned tuples.
Modifies type hints for other methods using the results of these methods so that they share the same definitions imported across different files.
How I tested this
Used the following small sample code to test these return types.
test code (click me)
Notes for Reviewers
This PR introduces 6 new
mypy
errors.I think this is a result of how
mypy
deals with overwriting a local variable with a different type than the first type it was instantiated with.I believe investigating and fixing these will be non-trivial, and I'm proposing that we defer fixing them to separate PRs targeting #3867.