SIGN IN SIGN UP
Textualize / rich UNCLAIMED

Rich is a Python library for rich text and beautiful formatting in the terminal.

0 0 89 Python

perf: reduce Console and RichHandler import time by deferring unused imports

Defer module-level imports that are only needed in specific code paths:

- logging.py: defer Traceback to emit() (only when rich_tracebacks=True)
- logging.py: use future annotations + TYPE_CHECKING for Console,
  ConsoleRenderable, Highlighter, FormatTimeCallable (annotation-only)
- logging.py: replace pathlib.Path with os.path.basename
- console.py: eliminate import inspect (~10ms); replace isclass with
  isinstance(x, type), currentframe with sys._getframe
- console.py: defer pretty to Console.print()
- console.py: defer scope to Console.log() (only when log_locals=True)
- console.py: defer getpass to Console.input() (only when password=True)
- console.py: defer html.escape and zlib to export methods
- segment.py: remove dead logging import (getLogger never used)
- theme.py: defer configparser to Theme.from_file()

Combined effect (Standard_D2s_v5, CPython 3.13, hyperfine):
  Console import: 78.8ms → 52.0ms (1.52x faster)
  RichHandler import: 99.4ms → 50.0ms (2.0x faster)
K
Kevin Turcios committed
b17c6169a4188d4a0ecb0153072a0061e62b8ec7
Parent: fc41075