invalid-lazy-import / E0403ΒΆ
Message emitted:
Lazy import is not allowed %s
Description:
Emitted when a PEP 810 ``lazy`` import is used where Python forbids it: inside a function, a class body or a ``try`` statement, or as a wildcard import. This is a SyntaxError.
Problematic code:
try:
lazy import json # [invalid-lazy-import]
except ImportError:
json = None
Correct code:
lazy import json
Additional details:
A lazy import (PEP 810) is only
allowed at module level, outside of any try statement, and never as a
wildcard import. Python raises a SyntaxError for the other positions, but
only when the module is compiled: the standard library's ast module parses
them without complaining, so pylint reports them itself.
Created by the imports checker.