Skip to content

Shrink libvt.__all__ behind PEP 562 and gate pytest11 imports #43

Done

Description

@tony

Summary

Wave 4 final pre-0.1.0 cutover slice of #34 (gated on Waves 1–3): shrink src/libvt/__init__.py to the quickstart core behind a static PEP 562 __getattr__ and __dir__ map, gate pytest11 startup imports in tests/test_libvt.py, and run a single mechanical cross-reference sweep across conftest.py, tests/, docs/, docs/project/public-api.md, and MIGRATION.

Motivation

  • .github/CONTRIBUTING.md requires src/libvt/pytest_plugin.py to keep top-level imports light during pytest collection, yet Python executes src/libvt/__init__.py first whenever libvt.pytest_plugin loads, eagerly importing libvt._ucd, libvt.terminal, libvt.graphics, and libvt.status into sys.modules.
  • Sequencing this slice in Wave 4—after Appearance, KnownEvent, libvt.profiles, and libvt.contrib.tmux sit in their final modules—lets __all__, Sphinx {class} targets, and MIGRATION update once instead of churning on every earlier wave.

Proposal

  • Replace eager submodule imports in src/libvt/__init__.py with from .__about__ import __version__, an if t.TYPE_CHECKING: static re-export block for ty / pyright / mypy, and a table-driven PEP 562 __getattr__ + __dir__ map serving only Terminal, Snapshot, Screen, Cell, Style, Appearance, Profile, Policy, Limits, Event, render, strip, LibVtError, ProtocolError, and __version__.
  • Preserve each class and function's defining submodule in __module__ (never rewriting __module__ = "libvt") so Sphinx autodoc, pickle, and tracebacks point to one canonical path (libvt.modes.Mode, libvt.input.KeyEvent, libvt.profiles.XTERM_PROFILE, libvt.contrib.tmux.decode_tmux_capture).
  • Add subprocess sys.modules assertions in tests/test_libvt.py verifying that import libvt and import libvt.pytest_plugin load neither libvt.terminal nor libvt._ucd, and that every name in libvt.__all__ resolves identically under runtime getattr(libvt, name) and static type checking.
  • Sweep remaining libvt.<attr> accesses in tests/, update _seed_doctest_namespace in conftest.py if needed, update MyST {class} / {func} targets across docs/ (just build-docs clean), and document relocated import paths in docs/project/public-api.md and MIGRATION.

Alternatives

  • Keeping all submodule symbols in libvt.__all__ behind lazy PEP 562 lookups: rejected because a flat package root freezes submodule symbol names across unrelated layers (codec, graphics, status, input, contrib) into permanent root API surface at 0.1.0.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions