Skip to content

Graph-local name resolution #160

@withtwoemms

Description

@withtwoemms

As a library user extending ucon with custom units
I want unit name resolution to be scoped to the active ConversionGraph
So I can define units that are visible only within a specific graph context without polluting global state


Acceptance Criteria

  • GIVEN a custom Unit registered via graph.register_unit(unit)
    WHEN get_unit_by_name(name) is called within using_graph(graph)
    THEN the custom unit must be returned.

  • GIVEN a custom Unit registered on graph A
    WHEN get_unit_by_name(name) is called within using_graph(graph_b) (a different graph)
    THEN the custom unit must NOT be found (raises UnknownUnitError or returns None).

  • GIVEN a unit name that exists in both graph-local and global registries
    WHEN get_unit_by_name(name) is called within using_graph(graph)
    THEN the graph-local unit must take precedence.

  • GIVEN a unit name that exists only in the global registry
    WHEN get_unit_by_name(name) is called within using_graph(graph)
    THEN the global unit must be returned (fallback behavior).

  • GIVEN a ConversionGraph
    WHEN graph.copy() is called
    THEN a new independent graph must be returned with copied name registries.

  • GIVEN the default graph built by _build_standard_graph()
    WHEN any standard unit name is queried via graph.resolve_unit(name)
    THEN the standard unit must be returned.

  • GIVEN case-sensitive unit shorthands (e.g., 'm' for meter, 'M' for mega prefix)
    WHEN graph.resolve_unit(name) is called
    THEN case-sensitive lookup must be attempted before case-insensitive fallback.

  • GIVEN nested using_graph() contexts
    WHEN the inner context exits
    THEN the outer graph must be restored for both conversion and name resolution.

Metadata

Metadata

Assignees

Labels

enhancementSome non-critical improvement of a feature; ergonomics

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions