-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: add checks for input types in Task
#64
Conversation
gcroci2
commented
Mar 28, 2024
•
edited
Loading
edited
- add checks for time vars
- add checks for all remaining input parameters, for all public methods
- fix tests
- add tests for checks
- ignore ANN401 in tests folder
Task
Task
Task
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.
Wouldn't it be easier to use an external package for enforcing type hints for most of these? Either pydantic or something like this (looks less stable, but was easier to find from documentation how to use do it) can do that.
If we stick to leaving it here, I would suggest to make it a bit more modular as per this comment
@@ -143,6 +143,7 @@ isort.known-first-party = ["annubes"] | |||
"S101", # Use of `assert` detected | |||
"ANN201", # Missing return type | |||
"D103", # Missing function docstring | |||
"SLF001", # private member access | |||
"SLF001", # Private member access | |||
"ANN401", # Function arguments annotated with too generic `Any` type |
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'm not a huge fan of this. I get that it's not pretty to turn it off many times over on individual functions, but I do think it's a good practice to avoid using Any
in most cases.
Alternatively, at the top of the test file in question, you can state AnyType = Any #noqa: ANN401, RUF100
as a type alias and then use AnyType wherever you don't want the linter to check without having to noqa each instance.
(the RUF100 ignoring isn't strictly necessary right now, but that is due to a bug in RUF, which I assume will be fixed at some point and then we won't have to fix it post-hoc).
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.
In the tests, you do want to test Any types. In the code-base I agree, that wouldn't be good. Very likely, we will need to state the exception at the beginning of each test file, so in my opinion is better to just set it in the toml directly on all tests files. This won't disable the error in the code-base, of course.
I'd go for pydantic, since the other one does not seem very reliable, especially for the future. Pydantic seems to have a dataclasses module, that may do the job.
As commented above, even if I agree that the checks can be definitely modularised more, it is not so trivial and it requires a bit of more careful edits. What if I open an issue for evaluating pydantic, and if that doesn't work then we open a PR for making what we have now more modular? |
Great idea! |
Quality Gate passedIssues Measures |