-
Notifications
You must be signed in to change notification settings - Fork 192
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
Feature/python typing/components command.py #2223
Feature/python typing/components command.py #2223
Conversation
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 wonder if we need to think quite carefully about the approach to type hinting within tools?
File-by-file seems like a good approach but would we benefit from some custom types (e.g. a pathlike = Union[str, Path]
being defined somewhere central that can be used across the codebase rather than redefining those sorts of unions in each file?
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 :)
After reading @awgymer comments, I think it makes sense to talk about it a bit more 🙂 |
Hi Novak I just pushed a commit to this PR to add mypy checks to the CI. This should help to make sure we don't add any conflicting type annotations. I am not sure if it is entirely correct, but we'll see the test once the CI runs. 👋 |
Codecov Report
@@ Coverage Diff @@
## dev #2223 +/- ##
==========================================
+ Coverage 70.60% 70.74% +0.14%
==========================================
Files 87 87
Lines 9437 9439 +2
==========================================
+ Hits 6663 6678 +15
+ Misses 2774 2761 -13
|
Changed components_utils->get_repo_info to return a tuple of three concrete types instead of a list of three Any types. Implemented suggestion to include self.dir as None. This was done in the __init__ argument typing
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.
Second try with a more conscious review, taking into account all the comments we have been discussing :)
My line of thought was to only annotate variables which are class arguments or declared such empty lists, etc. Feel free to disagree! 🙂
I have never used If I am wrong about how |
As it stands, mypy will fail every time we run tests. Doing a thorough check breaks on third-party library imports (first lines of .py files). The current repo doesn't include stubs for: Is it wise to create a new issue including stubs for these libraries? |
The mypy config in the pyproject.toml should solve the missing stub issue. (in theory at least. hopefully...) |
fixed syntax error for ingroe_missing_imports and added follow_imports="skip"
The problem with that approach is that now it will add files to the checks even if someone just changes a docstring somewhere and then that is blocked unless the whole file is correctly type hinted because of previous - PR unrelated unrelated - false type annotations. It will create a greater mess than simply removing erroneous type hints now. @mashehu Please reconsider |
@fabianegli one problem I am having with eliminating repository-wide MyPy errors is that the typing of external packages can contradict itself, e.g.
here the output types of Do you have any good ideas in mind for addressing this? |
Summary:
I tried expanding the scope of MyPy to the entire repository and addressed all issues I could find by running MyPy locally (see c97ef6e). However, even if the repo passed locally the GHA CI threw a lot of new errors which I believe would be too time consuming to address during the Hackathon. @fabianegli you are welcome to create a new PR to expand the scope of MyPy to the entire repo, but @mashehu asked me to proceed with the limited scope. |
"because we can" Co-authored-by: Matthias Hörtenhuber <mashehu@users.noreply.github.com>
Co-authored-by: Matthias Hörtenhuber <mashehu@users.noreply.github.com>
no context for this arg ever being undefined Co-authored-by: Matthias Hörtenhuber <mashehu@users.noreply.github.com>
Co-authored-by: Matthias Hörtenhuber <mashehu@users.noreply.github.com>
Change typing based on nf_core.utils.determine_base_dir() outputs. A bit messy, but let's not increase the scope further. Co-authored-by: Matthias Hörtenhuber <mashehu@users.noreply.github.com>
This is exactly why type hints are useful. They tell us that what we coded together might not wrk as expected. It basically tells us that we need to handle the case when the environment variable is not found and os.environ.get() returns None, because None can not be joined. So to fix this, one should ask the question "What should tools do, when said environment variable is undefined?" and then adapt the code accordingly. |
PR checklist
Added types to the components_command.py
As this is the main component used in other components, let us nail this one!