-
Notifications
You must be signed in to change notification settings - Fork 2
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-checking investigation #68
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.
Just is not None:
checks according to PEP 8. I think I marked them all.
src/mud/examples/adcirc.py
Outdated
save_figure( | ||
f"si-{value}", save_path, close_fig=close_fig, dpi=dpi, bbox_inches="tight" | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
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.
hm, why doesn't flake8
complain about this?
my thinking was actually to check for both None
and ""
simultaneously.
Though perhaps the behavior of ""
is fine... realized I'm not actually sure what would happen (would it try to save to root or to cwd?)
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.
Also, beware of writing if x when you really mean if x is not None – e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!
the type is str
, and I did intend for ""
to evaluate in the same context (this is the only str
that evals to False), so I was "careful" in the sense that this recommendation suggests. Question is... was I right about my assumption that ""
is a bad argument to pass to save_figure
? I don't know what happens if you try yet. I would prefer "cwd" to be given by "."
which evals to True, but I can see an argument for both strings resulting in that behavior of saving to cwd.
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.
Either works. I think PEP8 is just there to make the code more clear and readable in this case. "" evaluates to None but if not explicitly stated it just obfuscates the code a bit.
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.
fwiw, i ended up doing this.
src/mud/examples/adcirc.py
Outdated
save_figure( | ||
"adcirc_full_ts", save_path, close_fig=close_fig, dpi=dpi, bbox_inches="tight" | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
src/mud/examples/adcirc.py
Outdated
dpi=dpi, | ||
bbox_inches="tight", | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
src/mud/examples/adcirc.py
Outdated
dpi=dpi, | ||
bbox_inches="tight", | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
src/mud/examples/adcirc.py
Outdated
dpi=dpi, | ||
bbox_inches="tight", | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
mud_prob.plot_params_2d(ax=ax, y=i, contours=True, colorbar=True) | ||
if i == 1: | ||
ax.set_ylabel("") | ||
if kwargs.get("save_path"): |
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.
Should be
if kwargs,get("save_path") is not None:
See PEP 8
) | ||
|
||
fig.tight_layout() | ||
if kwargs.get("save_path"): |
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.
Should be
if kwargs,get("save_path") is not None:
See PEP 8
src/mud/examples/poisson.py
Outdated
save_figure( | ||
"lam1", save_path, close_fig=close_fig, dpi=dpi, bbox_inches="tight" | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
src/mud/examples/poisson.py
Outdated
save_figure( | ||
"lam2", save_path, close_fig=close_fig, dpi=dpi, bbox_inches="tight" | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
src/mud/examples/poisson.py
Outdated
dpi=dpi, | ||
bbox_inches="tight", | ||
) | ||
if save_path: |
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.
Should be
if save_path is not None:
See PEP 8
46febc3
to
347ffaa
Compare
* switch to ini file * save figs to test_dir * Revert "switch to ini file" This reverts commit 597fccc. * linting * workflows should trigger for changes to tests * specify dependency ranges (#70) * specify dependency ranges I ended up trying to install mud on a computer with an older scikit-learn, and it ended up using the cache of like version 0.something, so I want to at least specify the major version we require for the more important libraries. * loosen matplotlib * 3.7 support is a pain... * typo * prevent warnings from numpy * specify build os, tools * fix flake8 E721 errors * [black] lint files * [black] notebook linting * cover more versions of python * type-checking investigation (#68) * print mypy and python versions in workflow * 'if save_path' used to fix 10 mypy errors * automatic fix using https://github.com/hauntsaninja/no_implicit_optional * post-fix linting * refactor to address C901: too complex * refactor to address C901: too complex * ignore C901 * fix typo * sort imports * if save_path is not None * no more 3.12 bc numpy 1.24 * fix all mypy issues with 1.8.0 * enforce old cli functionality * actions updates, experiments with 3.12 (#72) * experiment with 3.12 * loosen pandas for 3.12 * build updates * rename, try new build
https://github.com/mathematicalmichael/mud/actions/runs/3425141460/jobs/5705619794 failed in a way I can't seem to reproduce locally.
mypy src/mud tests
works fine for me, but perhaps there's a version difference in the github action that can explain things.In the runner:
In my env:
upgrading to
mypy==0.990
reproduces the error. This is a recent release.save_path
save_figure
acts more as "maybe save figure" and that's confusing, so while it's inefficient to do so (rather than renaming the function to include an awkward prependedmaybe_
), I'm updating the logic for whether to call this function to the calling function. i.e. I'm adding a bunch ofif save_path:
indent blocks, this avoids changing the defaults /docstrings and allows for the option to use the type hintOptional[str]
.no_implicit_optional
tool.