py-materials 3.7.0__tar.gz → 3.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {py_materials-3.7.0 → py_materials-3.8.0}/PKG-INFO +1 -1
- {py_materials-3.7.0 → py_materials-3.8.0}/pyproject.toml +8 -1
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/__init__.py +1 -1
- py_materials-3.8.0/src/pymat/py.typed +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/vis/__init__.py +8 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/vis/_model.py +57 -2
- py_materials-3.8.0/tests/test_vis_deltas.py +190 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/.gitignore +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/LICENSE +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/ceramics/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/electronics/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/gases/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/liquids/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/metals/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/plastics/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/catalog/scintillators/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/docs/decisions/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/mat-rs/data/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/core.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/ceramics.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/electronics.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/gases.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/liquids.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/metals.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/plastics.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/data/scintillators.toml +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/elements.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/enrichers.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/factories.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/loader.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/properties.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/registry.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/search.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/units.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/src/pymat/vis/adapters.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/__init__.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/_visual_compare.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/baselines/README.md +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/conftest.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/material_preview.html +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_adapters.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_apply_to.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_build123d_integration_examples.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_catalog.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_core.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_e2e_vis.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_enrichers.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_integration.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_loader.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_lookup.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_material_copy.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_properties.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_readme_examples.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_search.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_toml_integrity.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_uncertainties.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_vis.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_vis_inheritance.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_vis_override.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_visual_compare.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/test_visual_regression.py +0 -0
- {py_materials-3.7.0 → py_materials-3.8.0}/tests/visual_render.html +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: py-materials
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.8.0
|
|
4
4
|
Summary: Hierarchical material library for CAD applications with build123d integration
|
|
5
5
|
Project-URL: Homepage, https://github.com/MorePet/py-mat
|
|
6
6
|
Project-URL: Repository, https://github.com/MorePet/py-mat
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "py-materials"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.8.0"
|
|
8
8
|
description = "Hierarchical material library for CAD applications with build123d integration"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -50,6 +50,13 @@ Issues = "https://github.com/MorePet/py-mat/issues"
|
|
|
50
50
|
[tool.hatch.build.targets.wheel]
|
|
51
51
|
packages = ["src/pymat"]
|
|
52
52
|
|
|
53
|
+
# PEP 561: ship the ``py.typed`` marker so type checkers (mypy/pyright)
|
|
54
|
+
# know to read inline annotations rather than skipping the package as
|
|
55
|
+
# untyped. Required for the ``Unpack[VisDeltas]`` typing on
|
|
56
|
+
# ``Vis.override`` to take effect under ``mypy --strict``.
|
|
57
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
58
|
+
"src/pymat/py.typed" = "pymat/py.typed"
|
|
59
|
+
|
|
53
60
|
[tool.hatch.build.targets.sdist]
|
|
54
61
|
include = [
|
|
55
62
|
"src/pymat/**",
|
|
File without changes
|
|
@@ -41,6 +41,10 @@ from mat_vis_client import (
|
|
|
41
41
|
from mat_vis_client import get_client as _shared_client
|
|
42
42
|
from mat_vis_client import search as _client_search
|
|
43
43
|
|
|
44
|
+
# Domain types: re-exported so consumers can construct or type-hint
|
|
45
|
+
# without reaching into the private ``_model`` module.
|
|
46
|
+
from pymat.vis._model import FinishEntry, Vis, VisDeltas
|
|
47
|
+
|
|
44
48
|
# Material-accepting adapters: Three.js / glTF / MaterialX.
|
|
45
49
|
# Re-exported at top level so ``from pymat.vis import to_threejs`` works
|
|
46
50
|
# and tab completion on ``pymat.vis.`` surfaces the main cross-tool
|
|
@@ -146,6 +150,10 @@ __all__ = [
|
|
|
146
150
|
"get_manifest",
|
|
147
151
|
"seed_indexes",
|
|
148
152
|
"MatVisClient",
|
|
153
|
+
# Domain types — Vis dataclass + the override-kwargs TypedDict
|
|
154
|
+
"Vis",
|
|
155
|
+
"VisDeltas",
|
|
156
|
+
"FinishEntry",
|
|
149
157
|
# Material → external-format adapters (the main cross-tool handoff)
|
|
150
158
|
"to_threejs",
|
|
151
159
|
"to_gltf",
|
|
@@ -42,7 +42,11 @@ from pathlib import Path
|
|
|
42
42
|
from typing import TYPE_CHECKING, Any, ClassVar, TypedDict
|
|
43
43
|
|
|
44
44
|
if TYPE_CHECKING:
|
|
45
|
+
# ``Unpack`` is in stdlib ``typing`` from 3.11; pull from
|
|
46
|
+
# ``typing_extensions`` (transitive dep, always available in
|
|
47
|
+
# type-check contexts) so 3.10 type-checking also works.
|
|
45
48
|
from mat_vis_client import MatVisClient, MtlxSource
|
|
49
|
+
from typing_extensions import Unpack
|
|
46
50
|
|
|
47
51
|
|
|
48
52
|
class FinishEntry(TypedDict):
|
|
@@ -57,6 +61,49 @@ class FinishEntry(TypedDict):
|
|
|
57
61
|
id: str
|
|
58
62
|
|
|
59
63
|
|
|
64
|
+
class VisDeltas(TypedDict, total=False):
|
|
65
|
+
"""Typed kwargs accepted by :meth:`Vis.override`.
|
|
66
|
+
|
|
67
|
+
Used by static type checkers (pyright, mypy) via ``Unpack`` per PEP
|
|
68
|
+
692. Surfaces every valid override key as IDE completion and flags
|
|
69
|
+
typos like ``roughnes=`` at edit time, not runtime.
|
|
70
|
+
|
|
71
|
+
All keys are optional (``total=False``) — that's the override
|
|
72
|
+
contract. To "leave a field unchanged", *omit* the key. Runtime
|
|
73
|
+
validation of unknown kwargs lives in :meth:`Vis.override`; this
|
|
74
|
+
TypedDict is purely a typing layer and has no runtime effect.
|
|
75
|
+
|
|
76
|
+
Identity fields (``source``, ``material_id``, ``tier``) are typed
|
|
77
|
+
as bare ``str`` here even though the underlying ``Vis`` field is
|
|
78
|
+
``str | None``. Reason: ``override`` routes identity through
|
|
79
|
+
:meth:`Vis.set_identity`, which interprets ``None`` as "leave
|
|
80
|
+
unchanged" rather than "clear" — so passing ``None`` would silently
|
|
81
|
+
no-op. Typing the kwarg as ``str`` enforces the kwargs idiom (omit
|
|
82
|
+
to leave alone) and keeps the type-checker contract honest.
|
|
83
|
+
|
|
84
|
+
Scalar fields (``roughness``, ``metallic``, …) keep the ``| None``
|
|
85
|
+
union — ``None`` is a legitimate reset value there (passes through
|
|
86
|
+
``setattr`` directly).
|
|
87
|
+
|
|
88
|
+
The ``finish`` key is a sugar — not a Vis field but a property
|
|
89
|
+
setter that looks up in the ``finishes`` map and reassigns
|
|
90
|
+
identity. Treated separately by ``override``'s body.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
source: str
|
|
94
|
+
material_id: str
|
|
95
|
+
tier: str
|
|
96
|
+
finishes: dict[str, FinishEntry]
|
|
97
|
+
roughness: float | None
|
|
98
|
+
metallic: float | None
|
|
99
|
+
base_color: tuple[float, float, float, float] | None
|
|
100
|
+
ior: float | None
|
|
101
|
+
transmission: float | None
|
|
102
|
+
clearcoat: float | None
|
|
103
|
+
emissive: tuple[float, float, float] | None
|
|
104
|
+
finish: str # sugar — looks up in finishes map, reassigns identity
|
|
105
|
+
|
|
106
|
+
|
|
60
107
|
# Identity fields whose mutation invalidates the lazy texture cache.
|
|
61
108
|
# Kept as a module-level constant so `__setattr__` can check membership
|
|
62
109
|
# in O(1) without re-allocating a set each call.
|
|
@@ -329,7 +376,7 @@ class Vis:
|
|
|
329
376
|
super().__setattr__("_textures", {})
|
|
330
377
|
super().__setattr__("_fetched", False)
|
|
331
378
|
|
|
332
|
-
def override(self, **deltas:
|
|
379
|
+
def override(self, **deltas: "Unpack[VisDeltas]") -> Vis: # noqa: F821 — TYPE_CHECKING only
|
|
333
380
|
"""Return a new ``Vis`` with the given deltas applied; ``self``
|
|
334
381
|
is unchanged.
|
|
335
382
|
|
|
@@ -342,6 +389,10 @@ class Vis:
|
|
|
342
389
|
polished = steel.vis.override(roughness=0.3, finish="polished")
|
|
343
390
|
# steel.vis is unchanged; polished is independent.
|
|
344
391
|
|
|
392
|
+
For helper functions that build delta dicts at runtime, type
|
|
393
|
+
them as :class:`VisDeltas` (importable from ``pymat.vis``) —
|
|
394
|
+
IDE completion + mypy strict-mode static checks come for free.
|
|
395
|
+
|
|
345
396
|
Note: ``override`` is the runtime mirror of TOML grade override
|
|
346
397
|
(children inherit parent properties unless overridden). It is
|
|
347
398
|
NOT a flat field substitution like ``dataclasses.replace`` —
|
|
@@ -395,7 +446,11 @@ class Vis:
|
|
|
395
446
|
finish_invalidating_keys = identity_keys & {"source", "material_id"}
|
|
396
447
|
finish_invalidating = any(deltas[k] != getattr(new, k) for k in finish_invalidating_keys)
|
|
397
448
|
if identity_keys:
|
|
398
|
-
|
|
449
|
+
# Pop identity values explicitly so each kwarg keeps its
|
|
450
|
+
# declared type (the comprehension form widens to ``object``
|
|
451
|
+
# because the TypedDict has heterogeneous field types).
|
|
452
|
+
id_kwargs: dict[str, Any] = {k: deltas.pop(k) for k in list(identity_keys)}
|
|
453
|
+
new.set_identity(**id_kwargs)
|
|
399
454
|
|
|
400
455
|
for k, v in deltas.items():
|
|
401
456
|
# Caller-supplied ``finishes=`` must be deep-copied — storing
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""Tests for the ``VisDeltas`` TypedDict (#108).
|
|
2
|
+
|
|
3
|
+
``VisDeltas`` is the static-typing surface for ``Vis.override(**deltas)``
|
|
4
|
+
kwargs (PEP 692 ``Unpack``). It has no runtime behavior — the override
|
|
5
|
+
runtime validation is in ``Vis.override`` itself — so these tests pin:
|
|
6
|
+
|
|
7
|
+
- the TypedDict is importable from the public surface
|
|
8
|
+
- it stays in sync with the ``Vis`` field set + ``finish`` property
|
|
9
|
+
- a runtime-constructed dict matching the schema works as **deltas
|
|
10
|
+
(round-trip via ``Vis.override(**delta_dict)``)
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from dataclasses import fields
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import pytest
|
|
19
|
+
|
|
20
|
+
from pymat.vis import Vis, VisDeltas
|
|
21
|
+
from pymat.vis._model import FinishEntry
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestPublicSurface:
|
|
25
|
+
def test_visdeltas_importable_from_pymat_vis(self):
|
|
26
|
+
"""``from pymat.vis import VisDeltas`` works."""
|
|
27
|
+
assert VisDeltas is not None
|
|
28
|
+
|
|
29
|
+
def test_visdeltas_is_typeddict(self):
|
|
30
|
+
"""``VisDeltas`` is a TypedDict with all keys optional."""
|
|
31
|
+
# TypedDict subclasses expose __total__ (False for total=False)
|
|
32
|
+
assert getattr(VisDeltas, "__total__", True) is False
|
|
33
|
+
|
|
34
|
+
def test_finishentry_importable_too(self):
|
|
35
|
+
"""``FinishEntry`` (used inside VisDeltas) is also exposed."""
|
|
36
|
+
assert FinishEntry is not None
|
|
37
|
+
|
|
38
|
+
def test_vis_re_exported(self):
|
|
39
|
+
"""``Vis`` itself is now reachable from ``pymat.vis``."""
|
|
40
|
+
from pymat.vis._model import Vis as _ModelVis
|
|
41
|
+
|
|
42
|
+
assert Vis is _ModelVis
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TestVisDeltasMirrorsVisFields:
|
|
46
|
+
"""``VisDeltas`` must enumerate every public Vis field + ``finish``.
|
|
47
|
+
If a future PR adds (or removes) a Vis field but forgets to update
|
|
48
|
+
VisDeltas, this test breaks loudly."""
|
|
49
|
+
|
|
50
|
+
def test_all_public_vis_fields_in_visdeltas(self):
|
|
51
|
+
public_fields = {f.name for f in fields(Vis) if not f.name.startswith("_")}
|
|
52
|
+
delta_keys = set(VisDeltas.__annotations__)
|
|
53
|
+
# Every public Vis field must appear in VisDeltas
|
|
54
|
+
missing = public_fields - delta_keys
|
|
55
|
+
assert not missing, f"Vis fields missing from VisDeltas: {missing}"
|
|
56
|
+
|
|
57
|
+
def test_finish_property_in_visdeltas(self):
|
|
58
|
+
"""``finish=`` is a property setter, not a field — must be in
|
|
59
|
+
the TypedDict explicitly."""
|
|
60
|
+
assert "finish" in VisDeltas.__annotations__
|
|
61
|
+
|
|
62
|
+
def test_no_extra_keys_in_visdeltas(self):
|
|
63
|
+
"""VisDeltas should not contain keys that aren't real override
|
|
64
|
+
targets (private fields, methods, etc.)."""
|
|
65
|
+
public_fields = {f.name for f in fields(Vis) if not f.name.startswith("_")}
|
|
66
|
+
valid_extras = {"finish"} # the property setter
|
|
67
|
+
delta_keys = set(VisDeltas.__annotations__)
|
|
68
|
+
extras = delta_keys - public_fields - valid_extras
|
|
69
|
+
assert not extras, f"VisDeltas has unknown keys: {extras}"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class TestRuntimeRoundTrip:
|
|
73
|
+
"""A dict matching the VisDeltas schema can be unpacked into
|
|
74
|
+
``override(**)`` and produces the expected result."""
|
|
75
|
+
|
|
76
|
+
def test_unpack_partial_deltas_dict(self):
|
|
77
|
+
v = Vis(source="ambientcg", material_id="Metal012", roughness=0.3)
|
|
78
|
+
deltas: VisDeltas = {"roughness": 0.7, "metallic": 0.5}
|
|
79
|
+
v2 = v.override(**deltas)
|
|
80
|
+
assert v2.roughness == 0.7
|
|
81
|
+
assert v2.metallic == 0.5
|
|
82
|
+
assert v.roughness == 0.3 # unchanged
|
|
83
|
+
|
|
84
|
+
def test_unpack_with_finish(self):
|
|
85
|
+
v = Vis(
|
|
86
|
+
source="ambientcg",
|
|
87
|
+
material_id="Metal012",
|
|
88
|
+
finishes={
|
|
89
|
+
"brushed": {"source": "ambientcg", "id": "Metal012"},
|
|
90
|
+
"polished": {"source": "ambientcg", "id": "Metal049A"},
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
deltas: VisDeltas = {"finish": "polished", "roughness": 0.05}
|
|
94
|
+
v2 = v.override(**deltas)
|
|
95
|
+
assert v2._finish == "polished"
|
|
96
|
+
assert v2.material_id == "Metal049A"
|
|
97
|
+
assert v2.roughness == 0.05
|
|
98
|
+
|
|
99
|
+
def test_unpack_identity_change(self):
|
|
100
|
+
v = Vis(source="ambientcg", material_id="Metal012")
|
|
101
|
+
deltas: VisDeltas = {"source": "polyhaven", "material_id": "metal_01"}
|
|
102
|
+
v2 = v.override(**deltas)
|
|
103
|
+
assert v2.source == "polyhaven"
|
|
104
|
+
assert v2.material_id == "metal_01"
|
|
105
|
+
|
|
106
|
+
def test_unpack_empty_deltas(self):
|
|
107
|
+
v = Vis(source="ambientcg", material_id="Metal012", roughness=0.3)
|
|
108
|
+
deltas: VisDeltas = {}
|
|
109
|
+
v2 = v.override(**deltas)
|
|
110
|
+
assert v2 == v
|
|
111
|
+
assert v2 is not v
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class TestIdentityFieldsTypedAsStr:
|
|
115
|
+
"""``VisDeltas.source``/``material_id`` are typed as ``str`` (no
|
|
116
|
+
``| None``) even though the underlying Vis field is ``str | None``.
|
|
117
|
+
|
|
118
|
+
Reason: ``override`` routes identity through ``set_identity``, which
|
|
119
|
+
interprets ``None`` as "leave unchanged" — so passing ``source=None``
|
|
120
|
+
would silently no-op, not clear the field. Typing the kwarg as
|
|
121
|
+
bare ``str`` enforces the kwargs idiom (omit to leave alone) and
|
|
122
|
+
keeps the type-checker contract honest. Pin both the TypedDict
|
|
123
|
+
annotation and the runtime no-op behavior so a future "let users
|
|
124
|
+
pass None to clear" change has to update everything in lockstep.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def test_visdeltas_source_typed_as_str(self):
|
|
128
|
+
# ``from __future__ import annotations`` means values are stored
|
|
129
|
+
# as forward references — compare the rendered forward-ref arg
|
|
130
|
+
# string. Bare ``str`` (not a union with None).
|
|
131
|
+
anns = VisDeltas.__annotations__
|
|
132
|
+
for field_name in ("source", "material_id", "tier"):
|
|
133
|
+
ann = anns[field_name]
|
|
134
|
+
ann_str = ann.__forward_arg__ if hasattr(ann, "__forward_arg__") else str(ann)
|
|
135
|
+
assert ann_str == "str", f"{field_name}: expected 'str', got {ann_str!r}"
|
|
136
|
+
|
|
137
|
+
def test_runtime_source_none_is_silent_noop(self):
|
|
138
|
+
"""If a user disregards the type and passes ``source=None`` at
|
|
139
|
+
runtime, identity is left unchanged (matches set_identity
|
|
140
|
+
semantics). Documents the lying-type the typing fix prevents
|
|
141
|
+
statically."""
|
|
142
|
+
v = Vis(source="ambientcg", material_id="Metal012", tier="1k")
|
|
143
|
+
# Bypass type checker — this is the runtime path
|
|
144
|
+
v2 = v.override(**{"source": None}) # type: ignore[typeddict-item]
|
|
145
|
+
assert v2.source == "ambientcg" # NOT cleared
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class TestPyTypedMarkerShipped:
|
|
149
|
+
"""PEP 561 marker — without ``py.typed`` mypy refuses to read
|
|
150
|
+
annotations and the whole ``Unpack[VisDeltas]`` effort delivers
|
|
151
|
+
zero value to mypy users."""
|
|
152
|
+
|
|
153
|
+
def test_py_typed_present_in_package(self):
|
|
154
|
+
import pymat
|
|
155
|
+
|
|
156
|
+
pkg_dir = Path(pymat.__file__).parent
|
|
157
|
+
marker = pkg_dir / "py.typed"
|
|
158
|
+
assert marker.exists(), (
|
|
159
|
+
f"PEP 561 marker missing at {marker}. Without it, mypy "
|
|
160
|
+
f"strict-mode users get no benefit from VisDeltas typing."
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class TestRuntimeIsTypingOnly:
|
|
165
|
+
"""``Unpack[VisDeltas]`` is wrapped in ``if TYPE_CHECKING:`` —
|
|
166
|
+
confirm there's no runtime side effect: the actual signature is
|
|
167
|
+
still ``**deltas: Any``, kwarg validation is still done by
|
|
168
|
+
``override``'s body, unknown kwargs still raise ``TypeError``."""
|
|
169
|
+
|
|
170
|
+
def test_unknown_kwarg_still_raises(self):
|
|
171
|
+
"""The TypedDict doesn't enforce at runtime — the override
|
|
172
|
+
body's ``valid_keys`` check does. Unchanged from 3.7.0."""
|
|
173
|
+
v = Vis(source="x", material_id="y")
|
|
174
|
+
with pytest.raises(TypeError, match="roughnes"):
|
|
175
|
+
v.override(roughnes=0.5) # typo
|
|
176
|
+
|
|
177
|
+
def test_typing_extensions_only_imported_under_type_checking(self):
|
|
178
|
+
"""``typing_extensions`` is imported only inside ``if
|
|
179
|
+
TYPE_CHECKING:`` — must not be a runtime dependency. If a
|
|
180
|
+
future refactor accidentally promotes the import, this test
|
|
181
|
+
won't catch it (TYPE_CHECKING is False at runtime, so the
|
|
182
|
+
import never runs in either case), but the assertion below
|
|
183
|
+
documents intent."""
|
|
184
|
+
import pymat.vis._model as model
|
|
185
|
+
|
|
186
|
+
# The Unpack name should NOT exist as a module-level attr at runtime.
|
|
187
|
+
assert not hasattr(model, "Unpack"), (
|
|
188
|
+
"Unpack leaked out of TYPE_CHECKING block — would force "
|
|
189
|
+
"typing_extensions as a runtime dep"
|
|
190
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|