-
Notifications
You must be signed in to change notification settings - Fork 82
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
Reduced the type: ignore comments and allocated the structured dataclass #393
base: main
Are you sure you want to change the base?
Reduced the type: ignore comments and allocated the structured dataclass #393
Conversation
odxtools/cli/compare.py
Outdated
|
||
# name of the tool | ||
_odxtools_tool_name_ = "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.
commented out code
odxtools/cli/compare.py
Outdated
deleted_variants : List[str] | ||
service_changes : SpecsServiceDict | ||
#class extract_service_tabulation_data(TypedDict): | ||
# table: RichTable |
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.
commented out code
odxtools/cli/compare.py
Outdated
"changed_name_of_service"][0] or service_dict["changed_parameters_of_service"][0]: | ||
assert isinstance(service_dict["diag_layer"], str) | ||
"changed_name_of_service"] or service_dict["changed_parameters_of_service"]: | ||
# assert isinstance(service_dict["diag_layer"], str) |
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.
commented out code
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 principle, I like it. IMO -- besides the usual bits and pieces that need to be fixed -- for whatever reason it seems that a lot of unrelated formatting changes slipped into this (which makes reviewing it more difficult than it needs to be and also prevents the CI from passing). To fix the formatting, install yapf
and isort
via pip and run the reformat-source.sh script in the toplevel directory of your working copy...
|
||
SpecsServiceDict = Dict[str, Union[VariantName, VariantType, NewServices, DeletedServices, | ||
RenamedServices, ServicesWithParamChanges]] | ||
class SpecsServiceDict(TypedDict): |
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.
IMO that should better be an @dataclass
(and be renamed to ServiceSpecs
) instead of being a TypedDict
. Maybe I'm missing something, though. (the same applies to the other TypedDict
derivatives below.)
"changed_name_of_service"][0] or service_dict["changed_parameters_of_service"][0]: | ||
assert isinstance(service_dict["diag_layer"], str) | ||
if ( | ||
service_dict["new_services"] |
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 SpecsServiceDict
becomes a dataclass, this should change this to service_spec.new_services
(assuming you rename the service_dict
variable to service_spec
). I'm not sure if mypy can handle typed dictionaries properly, but IMO directly accessing the attributes is considerably less clunky...
or service_dict["changed_name_of_service"] | ||
or service_dict["changed_parameters_of_service"] | ||
): | ||
# assert isinstance(service_dict["diag_layer"], str) |
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.
please remove such obsolete code instead of commenting it out
list, # type: ignore[type-arg] | ||
service_dict["changed_parameters_of_service"])[2][service_idx] | ||
info_list = cast(list, service_dict["changed_parameters_of_service"])[ | ||
2 |
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.
that 2
seems too much of a magical number to me. Ideally, this would be something like
service_spec.changed_parameters.added_params
(or whatever the third entry of that list represents)
Hi @andlaus
Added these set of lines which is used to reduce the
type :ignore
comments incompare.py
file which increases the readability and to maintain a structured dict. Please check these line commits and let me know I can help on this regard.class SpecsServiceDict(TypedDict): diag_layer: str diag_layer_type: str new_services: List[str] # List of new service names deleted_services: List[DiagService] # List of deleted services renamed_service: List[Tuple[str, DiagService]] # List of (old_name, DiagService) changed_name_of_service: List[Tuple[str, DiagService]] # Similar to renamed_service changed_parameters_of_service: List[Tuple[str, DiagService, List[Union[str, int, float]]]] class SpecsChangesVariants(TypedDict): new_variants : List[str] deleted_variants : List[str] service_changes : SpecsServiceDict
Thanks
Vinoth Kannan