[python-package] use dataclass for CallbackEnv #6048
Merged
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 #3756.
Contributes to #3867.
Proposes converting
CallbackEnv
in the Python package to a dataclass.Also proposes removing uses of
import collections
in favor of importing only exactly what LightGBM needs from that module.Restating the benefits I mentioned when I last tried this in #5765,
dataclasses
are preferable tonamedtuple
in the following ways:mypy
to understand the expected types of properties@property
(just like normal classes)I realized today that "use
dataclassses
" and "drop Python 3.6 support" don't have to be coupled... I was wrong to suggest that coupling in #5765 and #6022 (comment).This proposes taking on the
dataclasses
package as a required dependency only for Python 3.6. For details on that mechanism, see PEP 508 and PEP 631:That package still exists on PyPI exactly for cases like this... it's intended to be used to continue to provide
dataclasses
support for Python 3.6: https://pypi.org/project/dataclasses/.