Skip to content

Vis.get(field=..., default=...) parameter shadows dataclasses.field #60

Open

Description

@gerchowl

Tier 1 — latent footgun

`src/pymat/vis/_model.py:371-380`:

def get(self, field: str, default: Any = None) -> Any:
    """..."""
    val = getattr(self, field, None)
    ...

The parameter name `field` shadows `dataclasses.field` (imported at module
top for the dataclass decorator — see line 40). Inside this method body,
any refactor that reaches for `field(default_factory=...)` or similar
silently grabs a string instead of the dataclass helper.

Fix

Rename the parameter:

def get(self, name: str, default: Any = None) -> Any:

All existing call sites use positional arg, so no breakage.

Test

Not strictly necessary (lint would catch some refactor regressions), but
pinning the public signature prevents a future change from re-adding the
collision:

def test_vis_get_param_is_name_not_field():
    import inspect
    from pymat.vis._model import Vis
    sig = inspect.signature(Vis.get)
    assert "name" in sig.parameters
    assert "field" not in sig.parameters  # don't shadow dataclasses.field
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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions