| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Can we have a convention for lazy imports
Sorry, something went wrong.
There was a problem hiding this comment.
Can we have a convention for lazy imports
Yes, given we don't have a convention, and the SC left it the details to linters and auto-formatters, let's generally follow the Ruff/isort convention:
import json
import os
import subprocess
from collections import defaultdict
from pathlib import Path
from typing import Final
lazy import ast
lazy import shutil
lazy from dataclasses import dataclass
Sorry, something went wrong.
|
Seeing #149321, I think this should wait till that is somewhat figured out. |
Sorry, something went wrong.
|
And both the commands from #149321 are working. The CIFuzz failures are unrelated network errors: 413.7 E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/universe/t/tcltk-defaults/tcl-dev_8.6.9+1_amd64.deb Connection failed [IP: 185.125.190.81 80] There's another outage: https://status.canonical.com/#/incident/KNms6QK9ewuzz-7xUsPsNylV20jEt5kyKsd8A-3ptQG1OfBTMZO_fBkVMmGqQC3NLBLamiI6KOEL7KpsobFJ4Q== |
Sorry, something went wrong.
|
CIFuzz now also passing. |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good to me, but I'm not very familiar with lazy imports.
Sorry, something went wrong.
|
I'm not sure this makes sense for the pyrepl modules. Aren't those essentially always going to want _colorize? |
Sorry, something went wrong.
|
I'm not sure the sqlite.__main__ lazy import is worthwhile? While it's not imported at top level, main will immediately import it with ArgumentParser() or get_theme a little later. |
Sorry, something went wrong.
NO_COLOR=1 ./python.exe is a thing, and gives you a colour-free REPL. But it still gets imported: ❯ NO_COLOR=1 ./python.exe Python 3.15.0a8+ (heads/3.15-lazy-_colorize:2d346d5a1ea, May 6 2026, 16:40:10) [Clang 17.0.0 (clang-1700.6.4.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> "_colorize" in sys.modules True So I'll remove that change. |
Sorry, something went wrong.
|
And reverted in sqlite3.__main__ as well. |
Sorry, something went wrong.
Documentation build overview11 files changed · ± 11 modified ± Modified |
Sorry, something went wrong.
Sorry, something went wrong.
|
Yes, pdb also seemed questionable to me since if you use pdb you'll almost certainly want the prompt, which will give you colors. |
Sorry, something went wrong.
There was a problem hiding this comment.
json.tool is also unnecessary, it uses colorize in main() which is the only interface to that module.
I haven't looked much into profiling, are there plausible code paths where that is being used that don't go through colorize? Same for unittest and doctest.
difflib and traceback seem OK, they're broad libraries and there are plenty of functions in there that don't need color.
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: I have made the requested changes; please review again. |
Sorry, something went wrong.
There was a problem hiding this comment.
A couple still seem questionable but the cost of an extra lazy import isn't that high, so I'm OK with this going in.
Sorry, something went wrong.
|
Thanks all! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Lazily import _colorize to avoid slow construction/import when not needed.
The easily testable:
Some indirect improvements:
traceback needs some extra handling: add a shutdown theme, so if it attempts to reify _colorize during shutdown when the import machinery is no longer around, it has a no-op fallback.
Also add ensure_lazy_imports tests.