Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deepcopy for CodedConcept.from_dataset() #205

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/highdicom/sr/coding.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
import logging
from typing import Any, Optional, Union

Expand Down Expand Up @@ -64,13 +65,15 @@ def __eq__(self, other: Any) -> bool:
whether `self` and `other` are considered equal

"""
this = Code(
self.value,
self.scheme_designator,
self.meaning,
self.scheme_version
)
return Code.__eq__(this, other)
if isinstance(other, (Code, CodedConcept)):
this = Code(
self.value,
self.scheme_designator,
self.meaning,
self.scheme_version
)
return Code.__eq__(this, other)
return super().__eq__(other)

def __ne__(self, other: Any) -> bool:
"""Compares `self` and `other` for inequality.
Expand Down Expand Up @@ -121,12 +124,9 @@ def from_dataset(cls, dataset: Dataset) -> 'CodedConcept':
'Dataset does not contain the following attribute '
f'required for coded concepts: {kw}.'
)
return cls(
value=dataset.CodeValue,
scheme_designator=dataset.CodingSchemeDesignator,
meaning=dataset.CodeMeaning,
scheme_version=getattr(dataset, 'CodingSchemeVersion', None)
)
concept = deepcopy(dataset)
concept.__class__ = cls
return concept

@classmethod
def from_code(cls, code: Union[Code, 'CodedConcept']) -> 'CodedConcept':
Expand Down