Skip to content

feat: #88 vis inheritance + #89 pymat[...] lookup + runnable examples (3.4.0)#96

Merged
gerchowl merged 2 commits intomainfrom
feature/88-vis-inherit-and-lookup
Apr 20, 2026
Merged

feat: #88 vis inheritance + #89 pymat[...] lookup + runnable examples (3.4.0)#96
gerchowl merged 2 commits intomainfrom
feature/88-vis-inherit-and-lookup

Conversation

@gerchowl
Copy link
Copy Markdown
Contributor

Summary

Unblocks build123d#1270 Materials-class adapt pass. Fixes the two bugs Bernhard reported (#88, #89) and adds a runnable cell-style example file wired into pytest.

Closes #88. Closes #89.

What's in

#88 — Grades inherit parent Vis

Before 3.4, a grade without its own [vis] TOML section had vis.source = None, forcing consumers to walk the parent chain manually. Fixed in src/pymat/loader.py — deep-copies parent._vis for grades without their own [vis], merges TOML overrides on top when present via new Vis.merge_from_toml() classmethod.

Matches the existing _add_child property-inheritance pattern. Runtime mutations stay per-material (isolated) — documented trade-off.

#89 — Exact lookup surface

  • pymat["Stainless Steel 304"] — module-level subscript via PEP 562-style class swap. Matches key / name / grade (case-insensitive, NFKC + whitespace-collapse). Raises KeyError on miss (with fuzzy suggestions) or ambiguity (with candidates).
  • pymat.search(q, exact=True) — list-returning exact variant. Now matches grade too (was missing — caught by falsify review).
  • in operator works via __contains__.
  • Non-string / empty / whitespace-only inputs raise cleanly.

Examples + test wiring

  • examples/build123d_integration.py — cell-style (# %%) runnable script mirroring the pattern build123d's author uses. Covers lookup, search, inheritance, adapters, shape integration, glTF export.
  • tests/test_build123d_integration_examples.py — executes the file top-to-bottom via runpy on every CI run. Any API drift breaks the example before it breaks downstream copy-paste.

Falsify review

Before implementing, the original design (deep-copy-at-access proxy for Vis) was refuted by three orthogonal reviewers:

  • Python idioms: pymat.get() collides with dict.get() convention, name_or_key is a polymorphic-string smell, __getitem__ is the idiomatic shape.
  • Edge cases: exact=True missing grade targets, ambiguity handling, normalization silence.
  • Implementation reality: Vis.from_toml can't merge — needs an explicit merger classmethod.

Final design consolidates all three → load-time deep-copy-with-merge, __getitem__ subscript, grade-aware exact=True, full NFKC normalization.

Test plan

  • 386 tests pass locally (was 329; +57 new).
  • Pre-commit hooks clean (ruff format, pymarkdown, typos, etc.).
  • examples/build123d_integration.py runs top-to-bottom green.
  • build123d glTF export round-trip pinned (carries material through today's path).

Versioning

Minor bump 3.3.0 → 3.4.0 — additive public API, one behavior change (the #88 inheritance fix, which was surprising-but-fixing). No breaking deprecations.

… (3.4.0)

Unblocks build123d#1270 Materials-class adapt pass. Fixes two bugs and
adds a cell-style example file wired into pytest so API drift breaks
the example before it breaks downstream.

#88 — Grades inherit parent Vis at load time
  - Loader deep-copies parent._vis for grades without [vis] TOML section
  - Vis.merge_from_toml() handles partial overrides (grade with just
    roughness=0.7 inherits rest from parent)
  - Matches existing _add_child properties-inheritance pattern
  - Runtime mutation stays isolated per-material (documented, intentional)
  - 21 tests in tests/test_vis_inheritance.py

#89 — Exact lookup + normalization + grade targets
  - pymat["..."] via module-level __getitem__ (PEP 562-style class swap)
  - Matches key / name / grade with NFKC + case-fold + whitespace-collapse
  - KeyError on miss lists fuzzy close matches; KeyError on ambiguity
    lists candidates
  - search(exact=True) matches grade too (caught by falsify review)
  - __contains__ mirrors __getitem__
  - 28 tests in tests/test_lookup.py

examples/build123d_integration.py
  - Cell-style (# %%) runnable script covering the full integration
    surface: pymat[...] lookup, search, vis inheritance, adapter output,
    shape.material + export_gltf
  - tests/test_build123d_integration_examples.py runs the whole file
    via runpy; cells assert inline. Any API drift goes red here first.

Falsify review
  - Original deep-copy-at-access proxy design was refuted on three
    orthogonal angles (Python idioms, edge cases, implementation reality)
  - Load-time deep-copy-with-merge chosen instead: simpler, matches
    existing convention, documented trade-off on runtime parent mutation

Replaces 3.3.0 with 3.4.0 — minor bump because new public API
(pymat[...], exact=True) is additive, no existing behavior changes
except the #88 inheritance fix which was surprising-but-fixing.

329 → 386 tests (+57 new).
@gerchowl gerchowl merged commit 048416f into main Apr 20, 2026
19 checks passed
@gerchowl gerchowl deleted the feature/88-vis-inherit-and-lookup branch April 20, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Non fuzzy search [BUG] Materials found by search lack the vis properties except the first one

1 participant