Skip to content

Commit 696e3d5

Browse files
committed
Preserve class in Link.clone
1 parent 4ad4bf6 commit 696e3d5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pystac/link.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def clone(self) -> "Link":
269269
Returns:
270270
Link: The cloned link.
271271
"""
272-
273-
return Link(
272+
cls = self.__class__
273+
return cls(
274274
rel=self.rel,
275275
target=self.target,
276276
media_type=self.media_type,

tests/test_link.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,10 @@ def test_canonical_item(self) -> None:
175175
def test_canonical_collection(self) -> None:
176176
link = self.CustomLink.canonical(self.collection)
177177
self.assertIsInstance(link, self.CustomLink)
178+
179+
def test_clone(self) -> None:
180+
link = self.CustomLink.from_dict(
181+
{"rel": "r", "href": "t", "type": "a/b", "title": "t", "c": "d", "1": 2}
182+
)
183+
cloned_link = link.clone()
184+
self.assertIsInstance(cloned_link, self.CustomLink)

0 commit comments

Comments
 (0)