-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] drop Python 3.6 support, use dataclasses #5765
Conversation
if TYPE_CHECKING: | ||
from .engine import CVBooster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://mypy.readthedocs.io/en/stable/runtime_troubles.html#import-cycles for an explanation of this.
Adding this pattern to avoid cyclical imports... engine.CVBooster
is needed for the type annotation on CallbackEnv.model
, but engine.py
also tries to import all of callback
's contents.
from . import callback |
Even though some dependencies have dropped support for python 3.6, (I think) we don't rely on any new functionality from them, so if the drop is only for using dataclasses I don't think it's worth it, mainly because of the reasoning described in #5006 (comment), I know a couple of companies that are still stuck with py36 and since 4.0.0 will have many new features I don't think users should miss out on those just for the sake of type hints on a couple of data structures. I'm not hardly against it though, if you feel it's time and think it's worth it I won't oppose. |
Thanks @jmoralez ! I think you're right, I shouldn't have coupled the "drop Python 3.6" decision together with this attempt to get slightly clearer type annotations. I'm going to close this and open some new PRs proposing replacing these |
This pull request has been automatically locked since there has not been any recent activity since it was closed. |
Contributes to #3756.
Contributes to #3867.
Inspired by discussions in #5672 (thanks @IdoKendo !).
This PR proposes the following:
collections.namedtuple
in the Python package withdataclasses.dataclass
Why use
dataclasses
?dataclasses
are preferable tonamedtuple
in the following ways:mypy
to understand the expected types of properties@property
(just like normal classes)Why drop support for Python 3.6?
dataclasses
has been a part of the Python standard library since Python 3.7 (https://docs.python.org/3/library/dataclasses.html).Python 3.6 reached end-of-life (stopped receiving even security fixes) in December 2021 (https://devguide.python.org/versions/).
Most of
lightgbm
's dependencies dropped Python 3.6 a long time ago, for example:pandas
in August 2020: Drop Python 3.6 support pandas-dev/pandas#35214dask
anddistributed
in December 2020: NEP 29 - Dropping Python version support dask/community#66numpy
in December 2020: MAINT: Remove remaining uses of Python 3.6. numpy/numpy#17898