Skip to content

Commit be548c6

Browse files
committed
Perserve class in Collection.clone
1 parent 060f3c9 commit be548c6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pystac/collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ def to_dict(self, include_self_link: bool = True) -> Dict[str, Any]:
638638
return d
639639

640640
def clone(self) -> "Collection":
641-
clone = Collection(
641+
cls = self.__class__
642+
clone = cls(
642643
id=self.id,
643644
description=self.description,
644645
extent=self.extent.clone(),

tests/test_collection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,9 @@ def test_from_file_returns_subclass(self) -> None:
388388
custom_collection = self.BasicCustomCollection.from_file(self.MULTI_EXTENT)
389389

390390
self.assertIsInstance(custom_collection, self.BasicCustomCollection)
391+
392+
def test_clone(self) -> None:
393+
custom_collection = self.BasicCustomCollection.from_file(self.MULTI_EXTENT)
394+
cloned_collection = custom_collection.clone()
395+
396+
self.assertIsInstance(cloned_collection, self.BasicCustomCollection)

0 commit comments

Comments
 (0)