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

Fix mypy errors on master branch #3977

Merged
merged 11 commits into from
Aug 9, 2024

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Aug 8, 2024

Summary

if self.solid_compat:
entries = self.solid_compat.process_entries(entries, clean=True, inplace=inplace, n_workers=n_workers)
return [entries]
return [entries] # DEBUG: incompatible return type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incompatible return type, self.solid_compat.process_entries returns list[AnyComputedEntry] and this method should return list[AnyComputedEntry] instead of list[list[AnyComputedEntry]]

Copy link
Member

Choose a reason for hiding this comment

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

maybe wrapping entries as [entries] was added before the above check?

if isinstance(entries, ComputedEntry):
    entries = [entries]

do any tests break when you just return entries?

Copy link
Member

Choose a reason for hiding this comment

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

just noticed that it says "preprocess entries" in the comment above so probably wasn't meant to return at all on this line. tests pass without it. can you confirm @rkingsbury?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, there should not have been a return statement on that line. I'm not sure when that was introduced (can't tell from the git blame) but that was actually a pretty serious bug. It was effectively preventing the aqueous compatibility scheme from doing anything when given default arguments.

Copy link
Contributor Author

@DanielYang59 DanielYang59 Aug 9, 2024

Choose a reason for hiding this comment

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

Looks like it was added two weeks ago in #3933 5c5b74d. Great intuition @janosh and thanks a lot for the confirmation

Copy link
Member

Choose a reason for hiding this comment

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

@rkingsbury can you think of a good test to add that would have caught this breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, there should not have been a return statement on that line. I'm not sure when that was introduced (can't tell from the git blame) but that was actually a pretty serious bug. It was effectively preventing the aqueous compatibility scheme from doing anything when given default arguments.

I have no recollection of why I would have added this return statement, sadly I think it's likely that I added it to do some sort of manual checking that it worked correctly when run with joblib and then failed to remove it. Sorry.

Copy link
Member

Choose a reason for hiding this comment

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

for once, mypy proves its worth 😄

in general, can't wait for materials science codes to be fully statically typed!

Copy link
Contributor

Choose a reason for hiding this comment

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

@rkingsbury can you think of a good test to add that would have caught this breaking change?

What I would have expected to happen is with default arguments, the ComputedEntry would be returned with the normal solid energy corrections (MaterialsProject2020Compatibility) but no aqueous corrections. I guess existing tests didn't catch it because many (even most) solids won't receive any Aqueous corrections when they are processed. It's only a few materials like diatomic gases and materials containing OH that would get the adjustment.

@janosh janosh marked this pull request as ready for review August 8, 2024 23:48
@janosh janosh added fix Bug fix PRs linting Linting and quality assurance types Type all the things labels Aug 8, 2024
@janosh janosh enabled auto-merge (squash) August 8, 2024 23:56
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @DanielYang59! 👍

@janosh janosh merged commit dbc68be into materialsproject:master Aug 9, 2024
33 checks passed
@DanielYang59 DanielYang59 deleted the fix-mypy-master branch August 9, 2024 01:27
@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Aug 9, 2024

Thanks for reviewing. There was one type error for io.cp2k I haven't got to fix, isn't it failing on your side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PRs linting Linting and quality assurance types Type all the things
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some type annotations errors when trying to merge master into my local development branch.
4 participants