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

Type hint and validate Instance and Solution dictionaries #100

Closed
wants to merge 13 commits into from

Conversation

leonlan
Copy link
Member

@leonlan leonlan commented May 2, 2023

Closes #99.

TODO

  • Validate Instance and Solution objects (see stash validate-typing)
  • Make a new validate module that validates the instance and solution outputs according to VRPLIB.

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (580386e) 100.00% compared to head (f28e057) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #100   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        18    +2     
  Lines          261       282   +21     
=========================================
+ Hits           261       282   +21     
Impacted Files Coverage Δ
vrplib/Instance.py 100.00% <100.00%> (ø)
vrplib/Solution.py 100.00% <100.00%> (ø)
vrplib/parse/parse_distances.py 100.00% <100.00%> (ø)
vrplib/parse/parse_solomon.py 100.00% <100.00%> (ø)
vrplib/parse/parse_solution.py 100.00% <100.00%> (ø)
vrplib/parse/parse_vrplib.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@leonlan leonlan changed the title Instance and Solution TypeDict TypedDict Instance and Solution May 2, 2023

for section in sections:
section, data = parse_section(section, instance)
instance[section] = data
instance[section] = data # type: ignore
Copy link
Member Author

@leonlan leonlan May 2, 2023

Choose a reason for hiding this comment

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

TypedDict requires string literals, but since I don't know what kinds of section are parsed I need to ignore this.

I'm not sure if it even makes sense to use a TypedDict if I ignore this line.

Copy link
Member Author

@leonlan leonlan May 5, 2023

Choose a reason for hiding this comment

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

It's OK. Even though this line is no longer checked, the returned instance is assumed to be of type Instance, which used by mypy to do static type checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

But if we do this, we also need to validate that the instance indeed follows the types as specified in Instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we can use pydantic for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Make a new validate module that validates the instance and solution outputs according to VRPLIB.

@leonlan leonlan changed the title TypedDict Instance and Solution Type and validate Instance and Solution dictionaries May 5, 2023
@leonlan leonlan changed the title Type and validate Instance and Solution dictionaries Type hint and validate Instance and Solution dictionaries May 5, 2023
@leonlan
Copy link
Member Author

leonlan commented Oct 4, 2023

Not continuing with this.

@leonlan leonlan closed this Oct 4, 2023
@leonlan leonlan deleted the improve-typing branch October 6, 2023 09:31
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.

Validate instance and solution data
1 participant