Examples¶
Missing lazy module¶
__lazy_modules__ = ["argparse"]
import argparse
import requests
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("url")
args = parser.parse_args()
response = requests.get(args.url, timeout=5)
print(response.status_code)
Diagnostic:
Unsorted list¶
Diagnostic:
Nested imports require exact name¶
Diagnostic:
Relative names are invalid in __lazy_modules__¶
Diagnostic:
Unused entry in __lazy_modules__¶
Diagnostic:
Duplicate entry in __lazy_modules__¶
Diagnostic:
Module accessed at module scope¶
Diagnostic:
Enclosing package listed as lazy¶
# file: a/b/c.py
__lazy_modules__ = ["a", "a.b", "requests"]
# Python 3.15+ equivalent
# lazy import a
# lazy import a.b
Diagnostics:
LZY402 module 'a' is an enclosing package for this file and should not be declared lazy
LZY402 module 'a.b' is an enclosing package for this file and should not be declared lazy
Lazy import inside suppress(ImportError) (Python 3.15+)¶
Diagnostic:
With a lazy import, the actual import happens at first use of the module, which
occurs outside the with suppress(ImportError): block. The suppression
therefore has no effect.
Redundant lazy and __lazy_modules__ declaration (Python 3.15+)¶
Diagnostic:
The lazy import keyword already makes the import lazy; listing the module in
__lazy_modules__ as well is redundant.
Module imported both eagerly and lazily (Python 3.15+)¶
Diagnostic: