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

Enforce strict mypy checks #5370

Merged
merged 43 commits into from
Jan 21, 2021
Merged

Enforce strict mypy checks #5370

merged 43 commits into from
Jan 21, 2021

Conversation

derlih
Copy link
Contributor

@derlih derlih commented Dec 24, 2020

What do these changes do?

Fix typing for mypy strict mode

Are there changes in behavior for the user?

no

Related issue number

#3927

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Dec 24, 2020
@derlih
Copy link
Contributor Author

derlih commented Dec 24, 2020

Locally I don't have this mypy errors in tests. :-(
@asvetlov @webknjaz Do we really need to run mypy on tests folder?

@webknjaz
Copy link
Member

Yes. The tests are code too.

@webknjaz
Copy link
Member

webknjaz commented Dec 25, 2020

Also, can't you granularly apply the strictness to certain packages via mypy.ini?

@derlih
Copy link
Contributor Author

derlih commented Dec 26, 2020

Yes. The tests are code too.

Well. It depends :-)
The purpose of the tests is to test correctness and functionality, but not the typing (since we using python and not c++).
I never applied type hints to tests for example. But for the code itself I usually put type hints.

@codecov
Copy link

codecov bot commented Dec 26, 2020

Codecov Report

Merging #5370 (eaee5aa) into master (3014db4) will decrease coverage by 0.00%.
The diff coverage is 96.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5370      +/-   ##
==========================================
- Coverage   97.17%   97.17%   -0.01%     
==========================================
  Files          41       41              
  Lines        8742     8768      +26     
  Branches     1402     1404       +2     
==========================================
+ Hits         8495     8520      +25     
- Misses        129      130       +1     
  Partials      118      118              
Flag Coverage Δ
unit 97.05% <96.83%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
aiohttp/web_protocol.py 86.41% <ø> (ø)
aiohttp/resolver.py 93.18% <50.00%> (ø)
aiohttp/web_runner.py 97.74% <66.66%> (ø)
aiohttp/http_parser.py 97.23% <91.30%> (+0.08%) ⬆️
aiohttp/helpers.py 96.68% <93.75%> (-0.21%) ⬇️
aiohttp/client_exceptions.py 98.33% <100.00%> (ø)
aiohttp/client_reqrep.py 97.53% <100.00%> (+<0.01%) ⬆️
aiohttp/connector.py 96.51% <100.00%> (ø)
aiohttp/cookiejar.py 98.78% <100.00%> (ø)
aiohttp/formdata.py 98.92% <100.00%> (ø)
... and 17 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 3014db4...eaee5aa. Read the comment docs.

@webknjaz
Copy link
Member

Type checking can reveal problems in test just like in any other code.

Makefile Outdated Show resolved Hide resolved
@derlih derlih force-pushed the mypy-strict branch 2 times, most recently from 9408e31 to 9a77c42 Compare December 27, 2020 12:49
@derlih derlih requested a review from webknjaz January 14, 2021 16:26
@@ -0,0 +1 @@
Use mypy --strict
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Use mypy --strict
Use ``mypy --strict``

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 71 to 72
{}, # type: ignore
{}, # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Could you specify which errors are getting ignored? I saw syntax like # type: ignore:SomeError somewhere but I can't recall if it's documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I was not aware of this syntax.

@derlih derlih requested a review from webknjaz January 18, 2021 17:26
self.body = (self.body,) # type: ignore
body = (self.body,)
else:
body = self.body
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a logic change unrelated to typing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've restored the logic

@derlih derlih requested a review from webknjaz January 20, 2021 09:52
@@ -299,7 +309,7 @@ def ws_protocol(self) -> Optional[str]:
return self._ws_protocol

@property
def compress(self) -> bool:
def compress(self) -> int:
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this instead of converting the return value right below?

session = ClientSession(timeout=500)
assert session.timeout == 500
timeout = ClientTimeout(total=500)
session = ClientSession(timeout=timeout)
Copy link
Member

Choose a reason for hiding this comment

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

Why can't session timeout accept int?

@derlih
Copy link
Contributor Author

derlih commented Jan 20, 2021

@webknjaz I removed all changes and specified only mypy error codes in type: ignore[code]

@webknjaz webknjaz changed the title mypy --strict Enforce strict mypy checks Jan 21, 2021
@webknjaz webknjaz merged commit 742a8b6 into aio-libs:master Jan 21, 2021
@aio-libs-github-bot
Copy link
Contributor

💔 Backport was not successful

The PR was attempted backported to the following branches:

  • ❌ 3.8: Commit could not be cherrypicked due to conflicts

@webknjaz
Copy link
Member

@derlih
Copy link
Contributor Author

derlih commented Jan 21, 2021

@derlih mind backporting this to 3.8? https://docs.aiohttp.org/en/stable/contributing.html#backporting

I will try to

derlih added a commit to derlih/aiohttp that referenced this pull request Jan 21, 2021
This change covers the entire codebase with strict typings
and makes the ignores granular.

PR aio-libs#5370 by @derlih.
(cherry picked from commit 742a8b6)

Co-authored-by: Dmitry Erlikh <derlih@gmail.com>
@derlih derlih mentioned this pull request Jan 21, 2021
5 tasks
webknjaz pushed a commit that referenced this pull request Jan 21, 2021
This change covers the entire codebase with strict typings
and makes the ignores granular.

PR #5370 by @derlih.
(cherry picked from commit 742a8b6)

Co-authored-by: Dmitry Erlikh <derlih@gmail.com>
@derlih derlih deleted the mypy-strict branch January 21, 2021 16:24
alandtse pushed a commit to alandtse/aiohttp that referenced this pull request Feb 14, 2021
This change covers the entire codebase with strict typings
and makes the ignores granular.

PR aio-libs#5370 by @derlih
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
This change covers the entire codebase with strict typings
and makes the ignores granular.

PR aio-libs#5370 by @derlih
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
This change covers the entire codebase with strict typings
and makes the ignores granular.

PR aio-libs#5370 by @derlih
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants