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

Added mypy POC and attempted to fix issues #1114

Merged
merged 4 commits into from
Aug 2, 2021

Conversation

AdamSaleh
Copy link
Contributor

Added mypy and attempted to fix issues resulting from additional type-annotations. Removed py36.

Things I am not sure about:

The calendar comparisons: https://github.com/fedora-infra/anitya/compare/master...AdamSaleh:anitya_mypy_poc?expand=1#diff-6d66ea3411d110aa6961c53b9437d5adcecd56119de31c6a7530df1aa15314c3R491

I might go over-board with the isInstance checks, so some things are not comparable that were before. Or I have uncovered bug in the implementation? :-) If it's the former, I would like to figure out a way how to do this with mypy.

The defaults (that are not None): https://github.com/fedora-infra/anitya/compare/master...AdamSaleh:anitya_mypy_poc?expand=1#diff-7c42726a003d98fb9eab5f791a56c51d0422dde1d49020ec105961e0eadbdea3R86

Some should be easy, i.e. empty-list can be used in most places instead of None, because it already is False-y.
Some I am not sure about, like default REGEX, e.t.c.

Typed dictionary: it is really cool for mypy to shout at you when you have typo in your dictionary keys. But there already is support for dictionaries that don't contain all of the keys, and we might want to use that instead of lots of {key : None} initialization

@AdamSaleh AdamSaleh requested a review from a team as a code owner June 2, 2021 10:35
Copy link
Contributor

@Zlopez Zlopez left a comment

Choose a reason for hiding this comment

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

I have a few things in the comments, but I have a few other things here:

.travis.yml Outdated
- stage: test
python: 3.6
env: TOXENV=py36
- python: 3.7
Copy link
Contributor

Choose a reason for hiding this comment

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

Why removing python 3.7?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add mypy to .travis.yml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because https://www.python.org/dev/peps/pep-0589/ - Typed Dict has been introduced in 3.8

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, could you reflect this change in setup.py, it's used for creating metadata for PyPi packages about supported python versions.

@@ -53,6 +53,16 @@ def split_by_match(regex: str, string: str) -> Tuple[str, str]:
return "", string


class SplitResult(TypedDict, total=True):
Copy link
Contributor

@Zlopez Zlopez Jun 2, 2021

Choose a reason for hiding this comment

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

I'm not a fan of having multiple classes in one .py file, but this looks good. I didn't knew about the TypedDict till now.

@codecov
Copy link

codecov bot commented Jun 4, 2021

Codecov Report

Merging #1114 (1acf897) into master (739ff1a) will decrease coverage by 0.15%.
The diff coverage is 90.47%.

❗ Current head 1acf897 differs from pull request most recent head ef7772e. Consider uploading reports for the commit ef7772e to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1114      +/-   ##
==========================================
- Coverage   97.34%   97.19%   -0.16%     
==========================================
  Files          64       64              
  Lines        4220     4241      +21     
  Branches      600      603       +3     
==========================================
+ Hits         4108     4122      +14     
- Misses         65       67       +2     
- Partials       47       52       +5     
Impacted Files Coverage Δ
anitya/mail_logging.py 94.73% <50.00%> (-5.27%) ⬇️
anitya/lib/versions/calver.py 94.30% <88.09%> (-2.14%) ⬇️
anitya/config.py 100.00% <100.00%> (ø)
anitya/db/models.py 99.49% <100.00%> (-0.51%) ⬇️
anitya/forms.py 93.18% <100.00%> (ø)
anitya/lib/backends/__init__.py 92.64% <100.00%> (+0.05%) ⬆️
anitya/lib/ecosystems/__init__.py 100.00% <100.00%> (ø)
anitya/lib/versions/base.py 100.00% <100.00%> (ø)
anitya/lib/versions/rpm.py 92.63% <100.00%> (+1.81%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc532c2...ef7772e. Read the comment docs.

Copy link
Contributor

@Zlopez Zlopez left a comment

Choose a reason for hiding this comment

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

I saw codecov complaining about some new lines not being tested, but it would decrease coverage only by 0.15%, so let's ignore this.

Could you do two last things?

  1. Add news file. See https://anitya.readthedocs.io/en/latest/contributing.html#release-notes for how. This will be a dev change
  2. Squash the commits together

@@ -0,0 +1,2 @@
Introduced static-type checking through inclusion of mypy in tox.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if towncrier can process multiline news file. Let's keep this only with mypy update.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you try to run towncrier --draft to test this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried it and it doesn't seems to be an issue.

@Zlopez
Copy link
Contributor

Zlopez commented Jul 21, 2021

@AdamSaleh Because the F34 is by default running on python 3.9, it would be nice to have this in as soon as possible. I deployed the new version of Anitya on staging today running F34 and it's has plenty of issues and this PR should solve them.

@Zlopez Zlopez force-pushed the anitya_mypy_poc branch from 1acf897 to c788725 Compare July 28, 2021 13:15
@Zlopez
Copy link
Contributor

Zlopez commented Jul 28, 2021

I continued on this PR, but there is one thing missing mypy.cfg. I found out, that the *.cfg was in .gitignore, which probably caused this issue.
@AdamSaleh Could you update the PR with mypy.cfg? I already fixed everything else, even added mypy job to .zuul.yaml. So if tox -e mypy was already working, it should be just a question of adding the mypy.cfg

@softwarefactory-project-zuul
Copy link

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

@Zlopez
Copy link
Contributor

Zlopez commented Jul 28, 2021

I added #1153 for Python 3.9 support, so no need to fix this here. I will fix any conflict that will arise from this.

@Zlopez Zlopez force-pushed the anitya_mypy_poc branch from c788725 to 8b34930 Compare July 28, 2021 15:30
@Zlopez
Copy link
Contributor

Zlopez commented Jul 28, 2021

I rebased the PR to latest master. So the tests are now run against Python 3.9.

@softwarefactory-project-zuul
Copy link

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

@softwarefactory-project-zuul
Copy link

Zuul encountered a syntax error while parsing its configuration in the
repo fedora-infra/anitya on branch master. The error was:

Job tox-mypy not defined

The error appears in the following project stanza:

project:
check:
jobs:
- tox-lint
- tox-format
- tox-mypy
- tox-python38
- tox-python39
- anitya-tox-docs
- tox-bandit
- tox-diff-cover

in "fedora-infra/anitya/.zuul.yaml@master", line 143, column 3

@softwarefactory-project-zuul
Copy link

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

@Zlopez
Copy link
Contributor

Zlopez commented Aug 2, 2021

It looks like you rewrote my changes :-/ and I did the same by doing git pull from this PR

@Zlopez
Copy link
Contributor

Zlopez commented Aug 2, 2021

I fixed the mypy zuul job, but it still doesn't work, although I don't understand the issue happening there

@Zlopez
Copy link
Contributor

Zlopez commented Aug 2, 2021

I was able to reset the branch to before git pull state and did a merge. Let's see if this fix the issue

@softwarefactory-project-zuul
Copy link

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Add missing requirements for tests

Signed-off-by: Michal Konečný <[email protected]>
@softwarefactory-project-zuul
Copy link

Build succeeded.

@Zlopez
Copy link
Contributor

Zlopez commented Aug 2, 2021

It looks like all the remaining issues are fixed.

@Zlopez Zlopez merged commit ec20b8f into fedora-infra:master Aug 2, 2021
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.

2 participants