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

Update all annotations and check with Mypy #520

Merged
merged 9 commits into from
Sep 30, 2024
Merged

Update all annotations and check with Mypy #520

merged 9 commits into from
Sep 30, 2024

Conversation

CodyCBakerPhD
Copy link
Contributor

fix #416, at long last

@CodyCBakerPhD CodyCBakerPhD self-assigned this Sep 27, 2024
Comment on lines -148 to +149
organized_messages: dict[str, Union[dict, list[InspectorMessage]]],
organized_messages: dict,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While this could probably be typed with more detail as was attempted originally, it turns out to be pretty tricky to do right so maybe someone can tackle that later on its own PR

if isinstance(neurodata_object, NWBFile):
return neurodata_object.container_source

return neurodata_object.get_ancestor("NWBFile").container_source # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type of ignore is a potentially interesting one - it's because I type a generic NWB-type object as a Python object so any of the special class methods like .get_ancestor naturally are more specific than that - so it would be cool to have a common base neurodata object in PyNWB that all types inherit from (does that already exist? For both datasets and their containers / groups?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(recommend making more specific typing improvements down the road, and when ready remove the ignores here)

Copy link
Contributor

Choose a reason for hiding this comment

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

There is the AbstractContainer class inherited from by both Container and Data types, but I don't know if there is a common base neurodata object specifically...

Definitely worth discussing for typing improvements later on

@CodyCBakerPhD CodyCBakerPhD marked this pull request as ready for review September 27, 2024 21:29
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 89.84615% with 33 lines in your changes missing coverage. Please review.

Project coverage is 86.83%. Comparing base (ea18bf6) to head (9069c18).
Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
src/nwbinspector/tools/_read_nwbfile.py 65.00% 7 Missing ⚠️
src/nwbinspector/checks/_time_series.py 82.85% 6 Missing ⚠️
src/nwbinspector/_nwb_inspection.py 86.36% 3 Missing ⚠️
src/nwbinspector/checks/_nwbfile_metadata.py 92.50% 3 Missing ⚠️
src/nwbinspector/testing/_testing.py 76.92% 3 Missing ⚠️
src/nwbinspector/_registration.py 91.66% 2 Missing ⚠️
src/nwbinspector/checks/_images.py 77.77% 2 Missing ⚠️
src/nwbinspector/inspector_tools/__init__.py 0.00% 2 Missing ⚠️
src/nwbinspector/utils/_utils.py 84.61% 2 Missing ⚠️
src/nwbinspector/_nwbinspector_cli.py 66.66% 1 Missing ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #520      +/-   ##
==========================================
+ Coverage   79.49%   86.83%   +7.33%     
==========================================
  Files          47       47              
  Lines        1390     1504     +114     
==========================================
+ Hits         1105     1306     +201     
+ Misses        285      198      -87     
Files with missing lines Coverage Δ
src/nwbinspector/_configuration.py 96.29% <100.00%> (+0.06%) ⬆️
src/nwbinspector/_dandi_inspection.py 98.07% <100.00%> (+76.50%) ⬆️
src/nwbinspector/_formatting.py 90.64% <100.00%> (+5.24%) ⬆️
src/nwbinspector/_organization.py 100.00% <100.00%> (ø)
src/nwbinspector/_types.py 95.83% <100.00%> (ø)
src/nwbinspector/checks/_behavior.py 100.00% <100.00%> (ø)
src/nwbinspector/checks/_ecephys.py 100.00% <100.00%> (ø)
src/nwbinspector/checks/_general.py 100.00% <100.00%> (ø)
src/nwbinspector/checks/_icephys.py 100.00% <100.00%> (ø)
src/nwbinspector/checks/_nwb_containers.py 97.67% <100.00%> (+1.24%) ⬆️
... and 17 more

@CodyCBakerPhD
Copy link
Contributor Author

@stephprince OK, sorry this one has quite a bit of a changelog (just a lot of the same things) - I tried excluding it piece by piece by the exclusion rules were not playing nice with pre-commit so went ahead and did it all

Copy link
Contributor

@stephprince stephprince left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for all the helpful comments and context information.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, PathType and FilePathType are still being used in a couple of places, but once I update those they should be able to be deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep that sounds like a plan, I just did what I had to do to make Mypy happy, which was to sometimes fix that and other times not

local_path = Path(testing_config["LOCAL_PATH"])
local_path.mkdir(exist_ok=True, parents=True)
testing_folder = Path(TESTING_FILES_FOLDER_PATH)
testing_folder.mkdir(exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
testing_folder.mkdir(exist_ok=True)
testing_folder.mkdir(exist_ok=True, parents=True)

might still be needed if nested directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I caution against doing that very stringly, because if a target path is formatted incorrectly by mistake (say, like a WindowsPath) then calling parents=True will cause that folder to be created even if the root makes no sense for the OS (such as UNIX)

Ran into that one a couple times before.

If you want to ensure specific parents exist, I suggest going through them one at a time to make sure they exist (from top to bottom of course)

src/nwbinspector/_formatting.py Show resolved Hide resolved
if isinstance(neurodata_object, NWBFile):
return neurodata_object.container_source

return neurodata_object.get_ancestor("NWBFile").container_source # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

There is the AbstractContainer class inherited from by both Container and Data types, but I don't know if there is a common base neurodata object specifically...

Definitely worth discussing for typing improvements later on

@CodyCBakerPhD CodyCBakerPhD merged commit c453b68 into dev Sep 30, 2024
38 checks passed
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.

Fully type-annotate package
3 participants