Skip to content

Extract Vis._identity_args() helper to unify delegate call signatures #65

Open

Description

@gerchowl

Tier 2 — small refactor

Three delegation sugar properties use three different call shapes for
the same identity triple, flagged by the adversarial review
(`src/pymat/vis/_model.py`):

# .mtlx — kwarg-style
return self.client.mtlx(self.source, self.material_id, tier=self.tier)

# .channels — positional
return self.client.channels(self.source, self.material_id, self.tier)

# .materialize — positional
return self.client.materialize(self.source, self.material_id, self.tier, output_dir)

If mat-vis-client ever makes `tier` keyword-only (`*, tier: str = "1k"`),
`.channels` + `.materialize` break while `.mtlx` keeps working — and the
breakage is silent-ish (`TypeError: got positional arg for keyword-only`).

Fix

def _identity_args(self) -> tuple[str, str, str]:
    """Return (source, material_id, tier) — the positional arg triple
    that mat-vis-client methods expect. Call guarded by has_mapping."""
    return (self.source, self.material_id, self.tier)

@property
def mtlx(self) -> MtlxSource | None:
    if not self.has_mapping:
        return None
    src, mid, tier = self._identity_args()
    return self.client.mtlx(src, mid, tier=tier)

# Same shape for .channels and .materialize.

Test

def test_identity_args_tuple(self):
    v = Vis(source="a", material_id="b", tier="2k")
    assert v._identity_args() == ("a", "b", "2k")

Plus: grep for every remaining `self.client.X(self.source, self.material_id, ...)`
and route through the helper. This is a consistency refactor — not
behavioral.

Why a helper instead of explicit calls everywhere

The helper makes it one place to update when mat-vis-client changes
signatures. Also provides a seam for testing (monkeypatch
`_identity_args` to return a fixture triple).

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

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions