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

[WIP] Add stub for Dataset and type Dataset element attributes #1940

Closed
wants to merge 10 commits into from

Conversation

scaramallion
Copy link
Member

@scaramallion scaramallion commented Nov 14, 2023

Describe the changes

  • Adds stubs module, stub for Dataset and element types
  • Adds type hints for Dataset attributes like Dataset.PatientName
  • Updates to 2023d version of DICOM Standard
  • Closes Potential idea for further typing #1485

I tried to narrow the types as much as possible, but I don't think you can escape having to cast as long as an element can be empty or be VM 1-n. We might consider dropping None for SQ and only allowing MutableSequence[Dataset], though.

I also hesitated over adding more manually defined types for elements apart from those few Image Pixel module ones because it's basically impossible to verify that they'll never be type 2C/3.

Anyway, I'll leave it up to you @darcymason to decide whether or not adding stubs is a good idea.

Tasks

  • Fix or feature added
  • Code typed and mypy shows no errors
  • Unit tests passing and overall coverage the same or better

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8e0c4a6) 97.74% compared to head (4ea226c) 97.74%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1940      +/-   ##
==========================================
- Coverage   97.74%   97.74%   -0.01%     
==========================================
  Files          63       63              
  Lines       10747    10742       -5     
==========================================
- Hits        10505    10500       -5     
  Misses        242      242              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@scaramallion scaramallion changed the title [WIP] Add stub for Dataset and type Dataset element attributes [MRG] Add stub for Dataset and type Dataset element attributes Nov 15, 2023
Copy link
Member

@mrbean-bremen mrbean-bremen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@@ -241,7 +241,7 @@ def setup_argparse():
root = tree.getroot()

# Check the version is up to date
dcm_version = root.find("{https://docbook.org/ns/docbook}subtitle")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I think I reviewed this and missed that this is the fix namespace.

"ReceivingPresentationAddress",
"PrivateInformationCreatorUID",
"PrivateInformation",
# Image Pixel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not generate these automatically? Do you need them before they are generated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, the Type 3 ones can be left for the autogen. The rest are Type 1 so I put them in manually to take advantage of the narrower type.

Actually, hold on. mypy will check the types in the stubs directory but doesn't actually seem to be using them.

@scaramallion scaramallion changed the title [MRG] Add stub for Dataset and type Dataset element attributes [WIP] Add stub for Dataset and type Dataset element attributes Nov 15, 2023
@scaramallion
Copy link
Member Author

OK, this won't work as is, probably needs proper discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential idea for further typing
2 participants