Skip to content

Commit b51c29c

Browse files
committed
Rename to NamePlaceholder
1 parent 18688f0 commit b51c29c

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .mixin import BaseElement
77

88

9-
class ElementReference(BaseModel):
9+
class PlaceholderName(BaseModel):
1010
"""A pydantic model that represents a reference to a named element.
1111
1212
This class behaves like a string (via __str__ and __eq__) but stores
@@ -19,7 +19,7 @@ class ElementReference(BaseModel):
1919
element: A reference to the resolved element object (None until resolved)
2020
2121
Example:
22-
>>> ref = ElementReference(name="drift1")
22+
>>> ref = PlaceholderName(name="drift1")
2323
>>> ref.name
2424
'drift1'
2525
>>> str(ref)
@@ -65,7 +65,7 @@ def __eq__(self, other: object) -> bool:
6565
"""Enable string comparison."""
6666
if isinstance(other, str):
6767
return self.name == other
68-
if isinstance(other, ElementReference):
68+
if isinstance(other, PlaceholderName):
6969
return self.name == other.name and self.element is other.element
7070
return False
7171

src/pals/kinds/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .CrabCavity import CrabCavity # noqa: F401
1212
from .Drift import Drift # noqa: F401
1313
from .EGun import EGun # noqa: F401
14-
from .ElementReference import ElementReference # noqa: F401
1514
from .Feedback import Feedback # noqa: F401
1615
from .Fiducial import Fiducial # noqa: F401
1716
from .FloorShift import FloorShift # noqa: F401
@@ -27,6 +26,7 @@
2726
from .NullEle import NullEle # noqa: F401
2827
from .Octupole import Octupole # noqa: F401
2928
from .Patch import Patch # noqa: F401
29+
from .PlaceholderName import PlaceholderName # noqa: F401
3030
from .Quadrupole import Quadrupole # noqa: F401
3131
from .RBend import RBend # noqa: F401
3232
from .RFCavity import RFCavity # noqa: F401

src/pals/kinds/all_elements.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .CrabCavity import CrabCavity
1515
from .Drift import Drift
1616
from .EGun import EGun
17-
from .ElementReference import ElementReference
17+
from .PlaceholderName import PlaceholderName
1818
from .Feedback import Feedback
1919
from .Fiducial import Fiducial
2020
from .FloorShift import FloorShift
@@ -90,6 +90,6 @@ def get_all_elements_as_annotation(extra_types: tuple = None):
9090
Pydantic will still properly validate the union by trying each type in order in
9191
our unpack_element_list_structure method.
9292
"""
93-
types = get_all_element_types(extra_types) + (ElementReference,)
93+
types = get_all_element_types(extra_types) + (PlaceholderName,)
9494
# We can't use discriminator with ElementReference in the union since it has no 'kind' field
9595
return Union[types]

src/pals/kinds/mixin/all_element_mixin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from . import BaseElement
8-
from ..ElementReference import ElementReference
8+
from ..PlaceholderName import PlaceholderName
99

1010

1111
def unpack_element_list_structure(
@@ -46,10 +46,10 @@ def unpack_element_list_structure(
4646
# An element can be a string that refers to another element
4747
if isinstance(item, str):
4848
# Wrap the string in an ElementReference object
49-
new_list.append(ElementReference(item))
49+
new_list.append(PlaceholderName(item))
5050
continue
5151
# An element can be an ElementReference instance directly
52-
elif isinstance(item, ElementReference):
52+
elif isinstance(item, PlaceholderName):
5353
# Keep the ElementReference as-is
5454
new_list.append(item)
5555
continue

tests/test_elements.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,14 @@ def test_BeamLine_with_string_references():
562562
assert len(beamline.line) == 3
563563

564564
# First element should be an ElementReference that behaves like the string "drift1"
565-
assert isinstance(beamline.line[0], pals.ElementReference)
565+
assert isinstance(beamline.line[0], pals.PlaceholderName)
566566
assert beamline.line[0] == "drift1"
567567
assert beamline.line[0].name == "drift1"
568568
assert beamline.line[0].element is None # Not yet resolved
569569
assert not beamline.line[0].is_resolved()
570570

571571
# Second element should be an ElementReference that behaves like the string "quad1"
572-
assert isinstance(beamline.line[1], pals.ElementReference)
572+
assert isinstance(beamline.line[1], pals.PlaceholderName)
573573
assert beamline.line[1] == "quad1"
574574
assert beamline.line[1].name == "quad1"
575575
assert beamline.line[1].element is None # Not yet resolved
@@ -591,14 +591,14 @@ def test_BeamLine_with_string_references():
591591
def test_ElementReference_direct():
592592
"""Test ElementReference creation and behavior directly"""
593593
# Test creation with positional argument
594-
ref1 = pals.ElementReference("test_element")
594+
ref1 = pals.PlaceholderName("test_element")
595595
assert ref1.name == "test_element"
596596
assert str(ref1) == "test_element"
597597
assert ref1 == "test_element"
598598
assert not ref1.is_resolved()
599599

600600
# Test creation with keyword argument
601-
ref2 = pals.ElementReference(name="another_element")
601+
ref2 = pals.PlaceholderName(name="another_element")
602602
assert ref2.name == "another_element"
603603
assert str(ref2) == "another_element"
604604
assert ref2 == "another_element"

0 commit comments

Comments
 (0)