Repository navigation
Conversation
Adopt flake8-lazy as a pre-commit hook so `__lazy_modules__` declarations stay correct over time, and apply it to the `pybind11` package. This defers module-level imports that are only used inside functions (`_version`, `commands`, and several stdlib modules in `__main__.py` and `setup_helpers.py`), cutting import-time overhead. setuptools and distutils are excluded from lazy recommendations: setuptools monkeypatches distutils, so a lazy import of a monkeypatched module is unsafe, and their submodules stay eager. The `__main__.py` imports of `_version` and `commands` are made absolute so the generated `__lazy_modules__` entries are absolute module names; a `__spec__.parent` reference would not type-check under mypy because `__spec__` is `Optional[ModuleSpec]`. Assisted-by: OpenCode:qwen3.8:27b-mlx
henryiii
commented
Dec 3, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adding lazy imports. This was made will fully local AI and the flake8-lazy skill. :)
🤖 Human guided, AI assisted PR (using this skill). AI text below. 🤖
Description
Adopt flake8-lazy as a pre-commit
hook and apply it to the
pybind11package. This adds__lazy_modules__(PEP 810) declarations that defer module-level imports used only inside
functions —
_version,commands, and several stdlib modules in__main__.pyandsetup_helpers.py— cutting import-time overhead.setuptools/distutilsare excluded from lazy recommendations via--lazy-exclude-modules, because setuptools monkeypatches distutils and alazy import of a monkeypatched module is unsafe.
__main__.pyimports of_version/commandsare made absolute so thegenerated declarations are absolute module names; a
__spec__.parentreference would not type-check under mypy (
__spec__isOptional[ModuleSpec]).Suggested changelog entry:
pybind11package via flake8-lazy,deferring imports only used inside functions to cut import-time overhead.
Assisted-by: OpenCode:qwen3.8:27b-mlx