Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 72fca37

Browse files
committed
Function to get the object on which the input sculpture is based
1 parent 89b4f2c commit 72fca37

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: sculpting/core.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
__all__ = (
1414
"Sculpture",
15+
"material_of",
1516
"AttributeMap",
1617
"attribute_map_for",
1718
"read_only_attribute_map_as",
@@ -252,4 +253,11 @@ def _attribute_value_for(self, attribute_name: str, attribute_map: AttributeMap[
252253
return attribute_map.getter(self.__original)
253254

254255
def _set_attribute_value_for(self, attribute_name: str, attribute_value: Any, attribute_map: AttributeMap[OriginalT]) -> Any:
255-
return attribute_map.setter(self.__original, attribute_value)
256+
return attribute_map.setter(self.__original, attribute_value)
257+
258+
259+
material_of: Callable[[Sculpture[OriginalT]], OriginalT] = documenting_by(
260+
"""Function to get the object on which the input sculpture is based."""
261+
)(
262+
getattr |by| "_Sculpture__original"
263+
)

Diff for: tests.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,9 @@ def test_sculpture_attribute_mapping(
169169

170170
setattr(sculpture, virtual_attribute_name, new_attribute_value)
171171

172-
assert getattr(sculpture, virtual_attribute_name) == getattr(mapped, original_attribute_name)
172+
assert getattr(sculpture, virtual_attribute_name) == getattr(mapped, original_attribute_name)
173+
174+
175+
@mark.parametrize("obj", [(AttributeKeeper(value=42), 42, None)])
176+
def test_original_from(obj: object):
177+
assert material_of(Sculpture(obj)) is obj

0 commit comments

Comments
 (0)