using-lazy-import-in-unsupported-version / W2608ΒΆ
Message emitted:
Lazy imports are not supported by all versions included in the py-version setting
Description:
Used when the py-version set by the user is lower than 3.15 and pylint encounters the ``lazy`` import added by PEP 810.
Problematic code:
lazy import statistics # [using-lazy-import-in-unsupported-version]
def average_price(prices):
return statistics.mean(prices)
Correct code:
def average_price(prices):
import statistics # pylint: disable=import-outside-toplevel
return statistics.mean(prices)
Configuration file:
[main]
py-version=3.14
Additional details:
Lazy imports were introduced in Python 3.15, and older versions cannot compile a
module that contains one. This message is emitted as long as the py-version
setting still includes one of those older versions.
Once you no longer support them, raise py-version to 3.15. Until then, use a
regular import: placing it inside the function that needs it also delays it
until that function runs.
Created by the unsupported_version checker.