-
-
Notifications
You must be signed in to change notification settings - Fork 471
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
Potential idea for further typing #1485
Comments
It depends how accurate you want to be For VR DS, probably the worst, the type can be:
which is super unfun But most elements are either You'd still need to cast the results from Another option is to have a giant stub file for StrType = Union[None, str, MutableSequence[str]]
PersonNameType = Union[None, str, MutableSequence[str], PersonName, MutableSequence[PersonName]]
BytesType = Optional[bytes]
class Dataset:
PatientName: PersonNameType
PatientID: StrType
...
PixelData: BytesType |
Yup, that'd certainly help, and it would best be an autogenerated file built from the
For now I've just been utilising it for a block of private tags that I am utilising. Here is an example of how I have built out SequenceTag and BytesTag. I would expect that a file like this would be autogenerated. STORAGE_SEQUENCE_OFFSET = 0x00
DATASET_GROUPING_OFFSET = 0x80
StorageSequenceTag = tuple[TagGroup, Literal[0x1000]]
STORAGE_SEQUENCE_TAG = cast(
StorageSequenceTag, (TAG_GROUP, 0x1000 + STORAGE_SEQUENCE_OFFSET)
)
ParentSequenceTag = tuple[TagGroup, Literal[0x1010]]
PARENT_SEQUENCE_TAG: ParentSequenceTag = (TAG_GROUP, 0x1010)
SearchIndexSequenceTag = tuple[TagGroup, Literal[0x1060]]
SEARCH_INDEX_SEQUENCE_TAG: SearchIndexSequenceTag = (TAG_GROUP, 0x1060)
EncryptedDataTag = tuple[TagGroup, Literal[0x1050]]
ENCRYPTED_DATA_TAG: EncryptedDataTag = (TAG_GROUP, 0x1050)
EncryptedIndexHashTag = tuple[TagGroup, Literal[0x1070]]
ENCRYPTED_INDEX_HASH_TAG = (TAG_GROUP, 0x1070)
DatasetGroupingTag = tuple[TagGroup, Literal[0x1080]]
DATASET_GROUPING_TAG = cast(
DatasetGroupingTag, (TAG_GROUP, 0x1000 + DATASET_GROUPING_OFFSET)
)
SequenceTag = Union[StorageSequenceTag, ParentSequenceTag, SearchIndexSequenceTag]
BytesTag = Union[EncryptedDataTag, EncryptedIndexHashTag, DatasetGroupingTag] Also, I don't actually know how to remove the duplication with Literal types and their values. Having to write each tag value twice bugs me... eg: EncryptedIndexHashTag = tuple[TagGroup, Literal[0x1070]] # 0x1070 here
ENCRYPTED_INDEX_HASH_TAG = (TAG_GROUP, 0x1070) # and 0x1070 written again here...
No actually, I haven't had to do that. It's been working a treat |
I have been fleshing out a
TypedDataset
which makes it so that depending on the tag literal value the dataelement returned is aware of its own VR within mypy:It has made the typing experience with
pydicom
be quite nice. I wanted to present the idea here to spark discussion.Cheers,
Simon
The text was updated successfully, but these errors were encountered: