Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.86k stars 451 forks source link

Hidden mypy errors #8189

Closed qstokkink closed 1 month ago

qstokkink commented 1 month ago

On our PR tester, we use mypy-1.11.2-cp39 and the type checks pass. However, when I run mypy-1.11.2-cp310 I see typing errors:

$ mypy -p src.tribler.core
src/tribler/core/restapi/webui_endpoint.py:40: error: Incompatible types in assignment (expression has type "FileResponse", variable has type "ClientResponse")  [assignment]
src/tribler/core/restapi/webui_endpoint.py:41: error: Property "content_type" defined in "HeadersMixin" is read-only  [misc]
src/tribler/core/restapi/webui_endpoint.py:41: error: Incompatible types in assignment (expression has type "str | None", variable has type "str")  [assignment]
src/tribler/core/restapi/rest_manager.py:264: error: Item "AbstractServer" of "AbstractServer | None" has no attribute "sockets"  [union-attr]
src/tribler/core/restapi/rest_manager.py:264: error: Item "None" of "AbstractServer | None" has no attribute "sockets"  [union-attr]
src/tribler/core/restapi/rest_manager.py:283: error: Item "AbstractServer" of "AbstractServer | None" has no attribute "sockets"  [union-attr]
src/tribler/core/restapi/rest_manager.py:283: error: Item "None" of "AbstractServer | None" has no attribute "sockets"  [union-attr]
src/tribler/core/restapi/file_endpoint.py:54: error: Incompatible types in assignment (expression has type "Path", variable has type "str")  [assignment]
src/tribler/core/restapi/file_endpoint.py:55: error: "str" has no attribute "is_dir"  [attr-defined]
src/tribler/core/restapi/file_endpoint.py:56: error: "str" has no attribute "parent"  [attr-defined]
src/tribler/core/restapi/file_endpoint.py:60: error: "str" has no attribute "iterdir"  [attr-defined]
src/tribler/core/restapi/file_endpoint.py:71: error: "str" has no attribute "parent"  [attr-defined]
src/tribler/core/restapi/file_endpoint.py:75: error: "str" has no attribute "resolve"  [attr-defined]
src/tribler/core/restapi/events_endpoint.py:257: error: "RequestHandler" has no attribute "_handler_waiter"  [attr-defined]
src/tribler/core/restapi/events_endpoint.py:258: error: "RequestHandler" has no attribute "_handler_waiter"  [attr-defined]
src/tribler/core/libtorrent/restapi/downloads_endpoint.py:411: error: Incompatible types in assignment (expression has type "int", target has type "str")  [assignment]
src/tribler/core/libtorrent/restapi/downloads_endpoint.py:413: error: Incompatible types in assignment (expression has type "bool", target has type "str")  [assignment]
src/tribler/core/libtorrent/restapi/downloads_endpoint.py:418: error: Incompatible types in assignment (expression has type "list[int]", target has type "str")  [assignment]
Found 18 errors in 5 files (checked 93 source files)

For some reason, our PR checks also scan 98 files instead of the 93 I get locally (Success: no issues found in 98 source files).

qstokkink commented 1 month ago

Now that I look at it, I think this is because we don't install the Tribler dependencies in the type-checking run.

qstokkink commented 1 month ago

Installing the requirements was indeed necessary to uncover these hidden errors. I'll fix them in the PR that exposes them.