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 'strict' Mypy linting #1527

Merged
merged 23 commits into from
Mar 23, 2024
Merged

Enable 'strict' Mypy linting #1527

merged 23 commits into from
Mar 23, 2024

Conversation

danieleades
Copy link
Contributor

@danieleades danieleades commented Feb 23, 2024

enables strict mypy linting

note that i've suppressed and allow-listed some existing errors.
This allow-list should not be allowed to grow over time, and ideally would be incrementally shrunk until it can be removed entirely.

The error suppressions can be resolved by refactoring, and by creating upstream type stubs for third-party libraries that are untyped in typeshed (out of scope of this PR!)

@danieleades
Copy link
Contributor Author

danieleades commented Mar 4, 2024

"just" 49 errors to go!
38 errors remaining

@danieleades
Copy link
Contributor Author

remaining errors:

copier/tools.py:192: error: Missing type parameters for generic type "Match"  [type-arg]
copier/template.py:385: error: Missing type parameters for generic type "dict"  [type-arg]
copier/main.py:866: error: Item "None" of "Template | None" has no attribute "url"  [union-attr]
copier/main.py:867: error: Item "None" of "Template | None" has no attribute "commit"  [union-attr]
copier/main.py:889: error: Argument 2 to "migration_tasks" of "Template" has incompatible type "Template | None"; expected "Template"  [arg-type]
copier/main.py:911: error: Argument "data" to "replace" of "Worker" has incompatible type "Mapping[str, Any]"; expected "dict[str, Any]"  [arg-type]
copier/main.py:914: error: Item "None" of "Template | None" has no attribute "url"  [union-attr]
copier/main.py:993: error: Argument 2 to "migration_tasks" of "Template" has incompatible type "Template | None"; expected "Template"  [arg-type]
copier/cli.py:83: error: Class cannot subclass "Application" (has type "Any")  [misc]
copier/cli.py:105: error: Class cannot subclass "Application" (has type "Any")  [misc]
copier/cli.py:158: error: Untyped decorator makes function "data_switch" untyped  [misc]
copier/cli.py:176: error: Untyped decorator makes function "data_file_switch" untyped  [misc]
tests/test_dirty_local.py:7: error: Module "pytest_gitconfig" does not explicitly export attribute "GitConfig"  [attr-defined]
tests/conftest.py:11: error: Module "pytest_gitconfig" does not explicitly export attribute "GitConfig"  [attr-defined]
Found 14 errors in 6 files (checked 46 source files)

@danieleades danieleades marked this pull request as ready for review March 14, 2024 07:58
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 94.38202% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 97.47%. Comparing base (4831baf) to head (6dd91f1).
Report is 2 commits behind head on master.

Files Patch % Lines
devtasks.py 0.00% 3 Missing ⚠️
copier/subproject.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1527      +/-   ##
==========================================
+ Coverage   97.30%   97.47%   +0.17%     
==========================================
  Files          48       48              
  Lines        4594     4603       +9     
==========================================
+ Hits         4470     4487      +17     
+ Misses        124      116       -8     
Flag Coverage Δ
unittests 97.47% <94.38%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danieleades danieleades changed the title [WIP] Enable 'strict' Mypy linting Enable 'strict' Mypy linting Mar 14, 2024
@danieleades
Copy link
Contributor Author

@sisp, @yajo this is now ready for review

pyproject.toml Outdated Show resolved Hide resolved
copier/cli.py Outdated Show resolved Hide resolved
@danieleades danieleades marked this pull request as draft March 17, 2024 17:06
danieleades and others added 3 commits March 17, 2024 17:09
Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
@danieleades danieleades marked this pull request as ready for review March 18, 2024 07:08
@danieleades
Copy link
Contributor Author

@pawamoy i could probably just keep tinkering with this for ever, but i think this is a place where I can draw a line under it. This is now ready for review

@danieleades danieleades requested a review from pawamoy March 18, 2024 07:09
@danieleades
Copy link
Contributor Author

@sisp, @yajo this is now ready for review

ping!

Copy link
Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

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

IMO it looks good, except for the style changes in cli.py. I'll revert them and push a fixup.

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

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

Fantastic work, @danieleades! 👌 Just a few minor remarks from my side.

copier/main.py Outdated
@@ -1,4 +1,5 @@
"""Main functions and classes, used to generate or update projects."""

Copy link
Member

Choose a reason for hiding this comment

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

Those empty lines were introduced by Ruff v0.3.0 (IIRC). Would you mind reverting those (and the other occurences), too? They aren't related to this PR.

pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
poetry.lock Outdated Show resolved Hide resolved
@danieleades danieleades requested a review from sisp March 23, 2024 10:33
@danieleades
Copy link
Contributor Author

what's causing those test failures?

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

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

The style changes in cli.py are still present (cc @pawamoy) and also the introduced empty line between a module doctstring and the first import, which is not needed by the Ruff version locked via Nix (IIRC).

@pawamoy
Copy link
Contributor

pawamoy commented Mar 23, 2024

Reverted style changes in cli.py. Will now revert blank lines at the top of modules. Race to the finish!

@pawamoy
Copy link
Contributor

pawamoy commented Mar 23, 2024

Done.

@sisp
Copy link
Member

sisp commented Mar 23, 2024

what's causing those test failures?

I suspect that postponed annotations don't play well with Plumbum in cli.py. Could you try reverting back to classical type annotations and see whether tests pass again?

@danieleades
Copy link
Contributor Author

what's causing those test failures?

I suspect that postponed annotations don't play well with Plumbum in cli.py. Could you try reverting back to classical type annotations and see whether tests pass again?

strange. i've not made any changes since these tests were last passing

copier/cli.py Show resolved Hide resolved
Copy link
Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

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

LGTM, too! 🎉 Thanks for the fantastic work, @danieleades and @pawamoy! 🙏

@sisp sisp merged commit 0c6b0b9 into copier-org:master Mar 23, 2024
20 of 21 checks passed
@danieleades danieleades deleted the mypy-strict branch March 23, 2024 12:34
@sisp
Copy link
Member

sisp commented Apr 7, 2024

Resolves #1441.

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.

3 participants