-
Notifications
You must be signed in to change notification settings - Fork 99
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
Enable many ruff checks #476
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: inknos The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0f96265
to
b2bc285
Compare
5f98cce
to
4f8faa8
Compare
The errors come from removing the deprecated typing imports for Dict, List, Tuple and Type. Specifically, list is used in place of List and it's shadowed by the |
88768a6
to
15d23f3
Compare
8533cf6
to
ea3a31c
Compare
80ee029
to
34b2d49
Compare
34b2d49
to
3be44da
Compare
podman/domain/images_manager.py
Outdated
@@ -31,6 +32,8 @@ | |||
|
|||
logger = logging.getLogger("podman.images") | |||
|
|||
builtin_list = list | |||
|
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.
From my reading:
import builtins
>>> builtins.list
is more explicit about what is happening in this code. We are stuck with the naming collision. I think the safety of the typing is more important than the code bloat this will introduce. Or we can stay with List[].
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.
typing.List
is deprecated, that's why we should move away from it if we can.
https://docs.python.org/3/library/typing.html#typing.List
I like your solution better though, it's more clear. I believe the list
shadowing will not be problematic for users though, but the ambiguity in returns would eventually flag unexpected errors in IDEs, testing, checkers and such.
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.
@jwhonce I updated the PR with your suggestion
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.
@inknos The joys of trying to graph type checking on a language that is not statically typed.
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 know...
3be44da
to
7f1eaee
Compare
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.
Some nits and some questions. Looking good!
Catching BaseException can make it hard to interrupt the program (e.g., with Ctrl-C) and can disguise other problems. Signed-off-by: Nicola Sella <[email protected]>
Checks for the use of the characters 'l', 'O', or 'I' as variable names. Signed-off-by: Nicola Sella <[email protected]>
F401: unused-import E402: module-import-not-at-top-of-file S101: assert Assertions are removed when Python is run with optimization requested (i.e., when the -O flag is present), which is a common practice in production environments. As such, assertions should not be used for runtime validation of user input or to enforce interface constraints. Signed-off-by: Nicola Sella <[email protected]> Unused import Signed-off-by: Nicola Sella <[email protected]>
Check for unused variables. Unused variables should be prefixed with '_' Signed-off-by: Nicola Sella <[email protected]>
More on why it is bad here: https://docs.astral.sh/ruff/rules/redefined-loop-name/ Signed-off-by: Nicola Sella <[email protected]>
Signed-off-by: Nicola Sella <[email protected]>
This is a quality of life improvement and it should be backward compatible with our previous set line-length Signed-off-by: Nicola Sella <[email protected]>
Fix sys.version_info comparisons and drop unsupported python code Furthermore, addresses UP008: super-call-with-parameters Super is not called with parameters anymore when the first argument is __class__ and the second argument is equivalent to the first argument of the enclosing method Signed-off-by: Nicola Sella <[email protected]>
It is recommended to use 2 or more to give the caller more context about warning Signed-off-by: Nicola Sella <[email protected]>
B024: abstract-base-class-without-abstract-method Usually, abstract classes with no abstract methods are flagged as incorrectly implemented because @abstract might have been forgotten. PodmanResource should be kept an abstract class to prevent the initialization of an instance of it Signed-off-by: Nicola Sella <[email protected]>
Bugbear checks usually check for design problems within the code. https://pypi.org/project/flake8-bugbear/ Signed-off-by: Nicola Sella <[email protected]>
This could be an exception and should be checked in the future but it is suppressed at the moment. Signed-off-by: Nicola Sella <[email protected]>
S603: subprocess-without-shell-equals-true This could be an exception or a false positive and since it's used on one single piece of code it is ok to ignore from now. Signed-off-by: Nicola Sella <[email protected]>
Bandit provides security checks and good practices suggestions for the codebase. https://pypi.org/project/flake8-bandit/ Signed-off-by: Nicola Sella <[email protected]>
Signed-off-by: Nicola Sella <[email protected]>
Fix errors for tyope annotation for list, dict, type and tuple Example: UP006: Use `list` instead of `List` for type annotation Signed-off-by: Nicola Sella <[email protected]>
Python Version is already set to be < 3.9 so this code will never run Signed-off-by: Nicola Sella <[email protected]>
Signed-off-by: Nicola Sella <[email protected]>
This suppresses A003 for `list` builtin. `typing.List`, `typing.Dict`, `typing.Tuple` and `typing.Type` are deprecated. Removing these annotations breaks the calls to `list` when they are done within the same class scope, which makes them ambiguous. Typed returns `list` resolve to the function `list` defined in the class, shadowing the builtin function. This change is not great but a proper one would require changing the name of the class function `list` and breaking the API to be fixed. Example of where it breaks: podman/domains/images_manager.py class ImagesManager(...): def list(...): ... def pull( self, ... ) -> Image | list[Image], [[str]]: ... Here, the typed annotation of `pull` would resolve to the `list` method, rather than the builtin. For the sake of readability, all builtin `list` calls are replaced in the class as `builtins.list`. Signed-off-by: Nicola Sella <[email protected]>
Signed-off-by: Nicola Sella <[email protected]>
7f1eaee
to
995f760
Compare
@jwhonce I addressed the Also, I removed the last commit as it was more like a placeholder for future ruff checks and I don't like it upstream but rather track it in a different way. |
Depends on #473