Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vinothk-master
Copy link

Hi @andlaus

Added these set of lines which is used to reduce the type :ignore comments in compare.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

@CLA-Mercedes-Benz
Copy link

CLA-Mercedes-Benz commented Feb 22, 2025

CLA assistant check
All committers have signed the CLA.


# name of the tool
_odxtools_tool_name_ = "compare"

"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

deleted_variants : List[str]
service_changes : SpecsServiceDict
#class extract_service_tabulation_data(TypedDict):
# table: RichTable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

"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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code

Copy link
Member

@andlaus andlaus left a 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):
Copy link
Member

@andlaus andlaus Feb 24, 2025

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"]
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants