Skip to content

fix: collapse module into single file and remove lazy import #4

Description

@redtux

Summary

The two-file architecture (spdx_markdown.py + _impl.py) with a __new__-based
lazy wrapper is solving a circular-import problem that does not exist, and
introduces a real isinstance() bug.

Current behavior

  1. SPDXMarkdown is a thin wrapper that resolves to _SPDXMarkdownImpl at
    instantiation time via __new__. The real class lives in _impl.py.
  2. _SPDXMarkdownImpl does not subclass SPDXMarkdown, so
    isinstance(formatter, SPDXMarkdown) returns False — a latent bug for any
    code relying on type checks.

Root cause

The split was motivated by a perceived circular import: the claim was that the
entry-point scanner would deadlock if spdx_markdown.py imported
commitizen.changelog_formats.markdown at module level. In reality:

  • Markdown is already in sys.modules when commitizen scans
    commitizen.changelog_format entry points — commitizen needs it internally
    for the built-in "markdown" format.
  • Nothing in commitizen.changelog_formats imports back into this package.
    There is no cycle.

Proposed fix

Collapse the two files into one. Remove the __new__ redirection, all
TYPE_CHECKING stubs, and the _resolve() machinery. SPDXMarkdown becomes a
direct subclass of Markdown.

See Plan 10 — Collapse _impl.py for the
full implementation plan.

Additional scope

  • Verify py.typed (PEP 561 marker) lands in the built wheel.
  • Run ruff check src/ after the swap — the staggered-import pattern was the
    sole cause of existing E402 violations.

Reference

  • Plan: docs/plans/10-collapse-impl.md

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions