Page MenuHomeSoftware Heritage

mypy: Fix errors after django*-stubs upgrade
ClosedPublic

Authored by anlambert on Jun 1 2022, 2:56 PM.

Details

Summary

Since the release of django-stubs v1.11.0 and djangorestframework-stubs v1.6.0,
the following mypy errors were raised:

[2022-05-31T14:11:53.618Z] mypy run-test-pre: PYTHONHASHSEED='808326189'

[2022-05-31T14:11:53.618Z] mypy run-test: commands[0] | mypy swh

[2022-05-31T14:12:05.715Z] swh/web/common/utils.py:104: error: Incompatible types in assignment (expression has type "Union[Any, str, List[object]]", target has type "Union[str, bytes]")

[2022-05-31T14:12:05.716Z] swh/web/common/identifiers.py:118: error: Incompatible types in assignment (expression has type "Union[Any, str, List[object]]", target has type "Union[str, bytes]")

[2022-05-31T14:12:05.716Z] swh/web/common/identifiers.py:153: error: Incompatible types in assignment (expression has type "Union[str, List[object]]", target has type "Union[str, bytes]")

[2022-05-31T14:12:05.716Z] swh/web/common/identifiers.py:157: error: Item "List[object]" of "Union[str, List[object]]" has no attribute "endswith"

[2022-05-31T14:12:05.716Z] swh/web/common/identifiers.py:158: error: Incompatible types in assignment (expression has type "Union[str, List[object]]", target has type "Union[str, bytes]")

[2022-05-31T14:12:05.716Z] swh/web/common/identifiers.py:160: error: Incompatible types in assignment (expression has type "Union[str, List[object]]", target has type "Union[str, bytes]")

[2022-05-31T14:12:06.627Z] swh/web/tests/utils.py:61: error: Argument "response" to "_assert_http_response" has incompatible type "_MonkeyPatchedWSGIResponse"; expected "HttpResponse"

[2022-05-31T14:12:06.627Z] swh/web/tests/utils.py:95: error: Argument "response" to "_assert_http_response" has incompatible type "_MonkeyPatchedWSGIResponse"; expected "HttpResponse"

[2022-05-31T14:12:06.627Z] swh/web/tests/conftest.py:24: error: Unused "type: ignore" comment

[2022-05-31T14:12:06.877Z] Found 9 errors in 4 files (checked 217 source files)

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build has FAILED

Patch application report for D7938 (id=28591)

Rebasing onto a3529323b9...

Current branch diff-target is up to date.
Changes applied before test
commit 6e52f32e3e842dbb68edf1fb220f18c7eef8a28d
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Wed Jun 1 14:53:41 2022 +0200

    mypy: Fix errors after django*-stubs upgrade

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1862/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1862/console

Harbormaster returned this revision to the author for changes because remote builds failed.Jun 1 2022, 3:18 PM
Harbormaster failed remote builds in B29673: Diff 28591!

Build has FAILED

Patch application report for D7938 (id=28591)

Rebasing onto a3529323b9...

Current branch diff-target is up to date.
Changes applied before test
commit 6e52f32e3e842dbb68edf1fb220f18c7eef8a28d
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Wed Jun 1 14:53:41 2022 +0200

    mypy: Fix errors after django*-stubs upgrade

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1863/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1863/console

Build has FAILED

Patch application report for D7938 (id=28591)

Rebasing onto a3529323b9...

Current branch diff-target is up to date.
Changes applied before test
commit 6e52f32e3e842dbb68edf1fb220f18c7eef8a28d
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Wed Jun 1 14:53:41 2022 +0200

    mypy: Fix errors after django*-stubs upgrade

Link to build: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1864/
See console output for more information: https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1864/console

Build is green

Patch application report for D7938 (id=28591)

Rebasing onto a3529323b9...

Current branch diff-target is up to date.
Changes applied before test
commit 6e52f32e3e842dbb68edf1fb220f18c7eef8a28d
Author: Antoine Lambert <anlambert@softwareheritage.org>
Date:   Wed Jun 1 14:53:41 2022 +0200

    mypy: Fix errors after django*-stubs upgrade

See https://jenkins.softwareheritage.org/job/DWAPPS/job/tests-on-diff/1865/ for more details.

jayeshv added inline comments.
swh/web/common/identifiers.py
118

There is a mypy error in the same line when using psycopg2 latest version.
https://jenkins.softwareheritage.org/blue/organizations/jenkins/DWAPPS%2Ftests-on-diff/detail/tests-on-diff/1861/pipeline

will this fix that as well?

Can query_params[k] really be not a string? why?

Can query_params[k] really be not a string? why?

Apparently it can also be a bytes.

This is the only way I found to fix those errors, I do not really understand where the List[object] type comes from in mypy errors, it seems
the main source of confusion for mypy here.

swh/web/common/identifiers.py
118

This errors are unrelated to psycopg2 but to the upgrade of django stubs for mypy.

FYI, we cannot use psycopg2 >= 2.9 with Django 2.2 (see D7927#206118).

This revision is now accepted and ready to land.Jun 1 2022, 6:26 PM