-
Notifications
You must be signed in to change notification settings - Fork 9
Add mypy to CI file #89
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
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.
Thank you.
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
# Conflicts: # plugins/module_utils/role.py
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
plugins/module_utils/role.py
Outdated
hypercore_dict = rest_client.get_record( | ||
"/rest/v1/Role/{0}".format(role_uuid), must_exist=must_exist | ||
) | ||
role = cls.from_hypercore(hypercore_dict) | ||
return role | ||
if hypercore_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.
@domendobnikar This is not needed since None case is already handled in the from_hypercore method
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.
Oh I forgot to remove the same check from from_hypercore
method.
Do we need to raise an exception if Role
is None
?
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.
It depends on the case, we have "must_exist" parameter that handles this.
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.
All from_hypercore methods have None check, so I would leave it there. Or is there any case where it is better to have it in other methods that call from_hypercore method?
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.
Get
methods should handle this. Like you said - we already have must_exist
implemented there, might as well have the None
check, so we have everything in one place.
It makes a small difference between:
from hypercore(cls, hypercore_data: dict[Any, Any])
vs from hypercore(cls, hypercore_data: Union[dict[Any, Any], None])
And the return statement:
-> Union[Role, None]
vs -> Role
We just have to pick one and stick to it. I think right now half the classes use it one way and half the other way.
At least the ones that I made. That's why I put it in here, didn't even check or think about it which is my mistake :)
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.
Yes you are right, not all have the None check in the from_hypercore method :) But since the majority have it, I would stick to this then.
""" | ||
One User is equal to another if it has ALL attributes exactly the same. | ||
This method is used only in tests. | ||
""" | ||
if not isinstance(other, Role): |
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.
@domendobnikar why is this needed? Isn't enough just to put "other: Role"? Anyway Role class is part of User module, where I need to add the type annotation, so I am also doing this in parallel with you, thus the comments...
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 is specifically for __eq__
methods. Since __eq__
is expecting an object of any type and by hinting only Role
you are trying to override that supertype so MyPy won't let you override it. Right now this works in code because you know you are only checking Role vs Role, but MyPy doesn't know that hence the NotImplemented
part.
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.
Aaa ok ok, thanks for the explanation!
One note @domendobnikar . There are still errors (https://github.com/ScaleComputing/HyperCoreAnsibleCollection/actions/runs/4082190817/jobs/7036274867)
It should be |
Oh ok will fix. |
I think here we should decide if we use "from future import annotations" or using typing. I think the recomended way is to use the first one. What do you think? |
We need to use |
Also for the tuple vs Tuple, list vs List, dict vs Dict... |
make mypy
commandutils
andRestClient