Skip to content

Provide a typed way to require a token source map #430

Description

@adamtheturtle

Context

Token.map is correctly typed as list[int] | None: some tokens have no source map. The built-in fence and html_block rules always populate it, but consumers of those tokens must still assert that map is non-None or add a defensive branch solely to narrow its type.

Proposal

Add an accessor such as Token.require_map() -> list[int] that raises a clear exception when no map is present. This preserves the optional type of map while allowing consumers to use mapped tokens without local assertions or lint suppressions.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions