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

Enable mypy strict mode #115

Merged
merged 8 commits into from
Sep 13, 2024
Merged

Enable mypy strict mode #115

merged 8 commits into from
Sep 13, 2024

Conversation

cgohlke
Copy link
Member

@cgohlke cgohlke commented Sep 13, 2024

Description

This PR enables stricter mypy checks and also tunes some pre-commit and pytest settings (follow-up #114):

  • Enable mypy strict and warn-unreachable flags.
  • Exclude phasorpy._phasorpy and some third party packages from mypy.
  • Fix errors in mypy strict mode (mostly missing types and ignore[no-any-return]).
  • Use https://github.com/psf/black-pre-commit-mirror because it's faster.
  • Do not allow prettier to always change line endings on Windows.
  • Configure pre-commit.ci.
  • Enable pytest to raise errors on deprecation warnings.
  • Disable static code analysis on Python 3.10 because mypy strict mode fails with old dependencies.
  • On macOS, skip failing tests of unused _blend_darken and _blend_lighten functions.

Release note

Summarize the changes in the code block below to be included in the
release notes:

Enable mypy strict mode

Checklist

  • The pull request title, summary, and description are concise.
  • Related issues are linked in the description.
  • New dependencies are explained.
  • The source code and documentation can be distributed under the MIT license.
  • The source code adheres to code standards.
  • New classes, functions, and features are thoroughly tested.
  • New, user-facing classes, functions, and features are documented.
  • New features are covered in tutorials.
  • No files other than source code, documentation, and project settings are added to the repository.

@cgohlke
Copy link
Member Author

cgohlke commented Sep 13, 2024

Hi @bruno-pannunzio : are you using a Mac? Do you have any idea why the _blend_darken and _blend_lighten Cython functions emit RuntimeWarning: invalid value encountered? Did you notice this on your system before? On Ubuntu and Windows no warnings are raised as expected. Those functions are checking for NaN input, just like the other Cython ufuncs do. We can probably mark the failing tests as xfail on macOS. What do you think?

https://github.com/phasorpy/phasorpy/actions/runs/10841795383/job/30086395612?pr=115#step:5:51

@cgohlke
Copy link
Member Author

cgohlke commented Sep 13, 2024

Since _blend_darken and _blend_lighten are not used in PhasorPy, I disabled the failing tests on macOS. Probably XCode erroneously optimizes the isnan checks away.

The decreased test coverage is due to an increase in lines of code for typing, which is not tested.

@bruno-pannunzio
Copy link
Contributor

Hi @cgohlke. I have no warnings running _blend_darken and _blend_lighten in my Mac. Also tests are not failing. I am not aware what this problem might lie.

I think we can skip those tests for Mac as you already did.

@cgohlke
Copy link
Member Author

cgohlke commented Sep 13, 2024

Hi @bruno-pannunzio : thanks for checking. I suspect it is a compiler optimization issue. GitHub Actions might have an older XCode version installed and it looks like this is fixed in the latest version.

@cgohlke cgohlke merged commit 4daa509 into phasorpy:main Sep 13, 2024
14 of 15 checks passed
@cgohlke cgohlke deleted the mypy-strict branch September 13, 2024 18:56
@cgohlke
Copy link
Member Author

cgohlke commented Sep 13, 2024

This seems like a good time to revisit the Repo-Review from the Scientific Python Library Development Guide.

  • They want ruff and mypy enabled in pre-commit. We discussed and postponed both.

  • They suggest enabling enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] for mypy. I'll look into that (fixed in Configure mypy enable_error_code #116).

  • Instead of blacken-docs we use blackdoc.

  • I do not agree on using either ReadTheDocs or a task runner.

  • Not sure why they recommend setting a custom pre-commit CI message. The default "[pre-commit.ci] pre-commit autoupdate" looks better than the replacement they suggest (fixed in Configure mypy enable_error_code #116).

  • The "upload-artifact" detection looks too strict on their side. We should update or replace the outdated release-pypi.yml before the release though.

@bruno-pannunzio : Any thoughts?

@bruno-pannunzio
Copy link
Contributor

Hi @cgohlke, sorry I couldn't answer before.

  • Instead of blacken-docs we use blackdoc.

I think blackdoc is better since it can also be used to apply black formatting to docstring in python files, which I find it quite useful. On the other hand blacken-docs only supports Markdown, reStructuredText, and LaTex files, if I understood correctly. So I think we should stick to blackdoc.

  • I do not agree on using either ReadTheDocs or a task runner.

I don't think we need tox or another task runner in our case, as you said, at least for now we are doing finde without it. Maybe we can revisit later if the community asks for it? Regarding ReadTheDocs, I think people are using it more and more to access documentation, but I wouldn't mind not having it since we have a very detailed and working documentation already. I believe you don't want to use ReadTheDocs to avoid duplicating documentation or is there another reason?

  • The "upload-artifact" detection looks too strict on their side. We should update or replace the outdated release-pypi.yml before the release though.

I am not aware of the benefits of using the suggested format for using unique names for "upload-artifact".

@cgohlke
Copy link
Member Author

cgohlke commented Sep 16, 2024

you don't want to use ReadTheDocs to avoid duplicating documentation or is there another reason?

They insert Ads.

I am not aware of the benefits of using the suggested format for using unique names for "upload-artifact"

I think they are referring to upload-artifact@v4, which requires unique names. Anyway, we already use unique upload names in the wheel builder (release-pypi.yml is outdated):

- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
name: wheels-${{ matrix.os }}

@bruno-pannunzio
Copy link
Contributor

Excellent, I totally agree. I then believe that we are covered regarding the Scientific Python Library and have deliberately made the modifications we think are better, at least for now. But maybe it's a good idea to revisit this with some regularity to make sure everything and we are aligned.

@cgohlke cgohlke mentioned this pull request Sep 16, 2024
@cgohlke
Copy link
Member Author

cgohlke commented Sep 16, 2024

maybe it's a good idea to revisit this with some regularity

Good idea. I opened issue #118 as a reminder.

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

Successfully merging this pull request may close these issues.

2 participants