-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
organized_messages: dict[str, Union[dict, list[InspectorMessage]]], | ||
organized_messages: dict, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
@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 |
There was a problem hiding this 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing_folder.mkdir(exist_ok=True) | |
testing_folder.mkdir(exist_ok=True, parents=True) |
might still be needed if nested directories?
There was a problem hiding this comment.
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)
if isinstance(neurodata_object, NWBFile): | ||
return neurodata_object.container_source | ||
|
||
return neurodata_object.get_ancestor("NWBFile").container_source # type: ignore |
There was a problem hiding this comment.
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
fix #416, at long last