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

Use a dedicated error code for assignment to method #14570

Merged
merged 4 commits into from
Feb 5, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #2427

If this will cause a too big fallout, we may need to add some special logic, so that type: ignore[assignment] will cover [method-assign].

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 1, 2023

If this will cause a too big fallout, we may need to add some special logic, so that type: ignore[assignment] will cover [method-assign].

I think that this would be good to have, since several projects are impacted by the change otherwise. After 1.0 release we want to avoid regressions whenever it's not too difficult.

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

Looks like the unused ignore logic also needs some futzing

@ilevkivskyi
Copy link
Member Author

After some thinking, IMO people who use --warn-unused-ignores want to see these errors (since assignment is a much wider code that can hide some bad type errors). So I keep them but make the error message more helpful, but pointing out to what exactly the user should do.

@AlexWaygood
Copy link
Member

AlexWaygood commented Feb 3, 2023

After some thinking, IMO people who use --warn-unused-ignores want to see these errors (since assignment is a much wider code that can hide some bad type errors).

flake8-pyi is one of the affected projects here in the mypy_primer diff, and I agree that I'd very much want to see these errors (as a maintainer of that project). This seems like a great solution to me.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2023

Diff from mypy_primer, showing the effect of this PR on open source code:

pip (https://github.com/pypa/pip)
- src/pip/_internal/network/session.py:246: error: Cannot assign to a method  [assignment]
+ src/pip/_internal/network/session.py:246: error: Cannot assign to a method  [method-assign]

flake8-pyi (https://github.com/PyCQA/flake8-pyi)
+ pyi.py:215: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ pyi.py:217: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/protobufs/msg.py:125: error: Cannot assign to a method  [assignment]
+ steam/protobufs/msg.py:125: error: Cannot assign to a method  [method-assign]

pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/vendor/decorator.py:295: error: Cannot assign to a method  [assignment]
+ pyinstrument/vendor/decorator.py:295: error: Cannot assign to a method  [method-assign]
- pyinstrument/vendor/decorator.py:301: error: Cannot assign to a method  [assignment]
+ pyinstrument/vendor/decorator.py:301: error: Cannot assign to a method  [method-assign]

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/util/docutils.py:220: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ sphinx/util/docutils.py:221: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ sphinx/util/docutils.py:227: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ sphinx/util/docutils.py:228: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]

core (https://github.com/home-assistant/core)
+ homeassistant/block_async_io.py:11: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ homeassistant/runner.py:76: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ homeassistant/helpers/schema_config_entry_flow.py:278: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]

dragonchain (https://github.com/dragonchain/dragonchain)
- dragonchain/lib/dto/eth_utest.py:51:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:51:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:72:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:72:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:77:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:77:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:88:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:88:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:115:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:115:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:123:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:123:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/eth_utest.py:131:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/eth_utest.py:131:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:51:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:51:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:56:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:56:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:61:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:61:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:62:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:62:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:70:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:70:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:77:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:77:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:84:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:84:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:90:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:90:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:101:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:101:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:108:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:108:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:114:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:114:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:120:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:120:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:125:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:125:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:131:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:131:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/btc_utest.py:138:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/btc_utest.py:138:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:73:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:73:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:78:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:78:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:84:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:84:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:109:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:109:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:118:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:118:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:119:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:119:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:122:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:122:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:123:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:123:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:131:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:131:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:140:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:140:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:149:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:149:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:156:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:156:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:164:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:164:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:170:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:170:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:173:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:173:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:180:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:180:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:183:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:183:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:192:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:192:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:322:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:322:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:331:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:331:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:338:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:338:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:339:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:339:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:347:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:347:9: error: Cannot assign to a method  [method-assign]
- dragonchain/lib/dto/bnb_utest.py:349:9: error: Cannot assign to a method  [assignment]
+ dragonchain/lib/dto/bnb_utest.py:349:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:238:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:238:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:239:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:239:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:466:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:466:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:467:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:467:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:481:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:481:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:482:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:482:9: error: Cannot assign to a method  [method-assign]
- dragonchain/transaction_processor/level_5_actions_utest.py:493:9: error: Cannot assign to a method  [assignment]
+ dragonchain/transaction_processor/level_5_actions_utest.py:493:9: error: Cannot assign to a method  [method-assign]

... (truncated 84 lines) ...

spark (https://github.com/apache/spark)
+ python/pyspark/sql/session.py:115: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ python/pyspark/pandas/frame.py:12100: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]
+ python/pyspark/pandas/frame.py:12113: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment]

discord.py (https://github.com/Rapptz/discord.py)
- discord/file.py:106: error: Cannot assign to a method  [assignment]
+ discord/file.py:106: error: Cannot assign to a method  [method-assign]
- discord/file.py:146: error: Cannot assign to a method  [assignment]
+ discord/file.py:146: error: Cannot assign to a method  [method-assign]
- discord/gateway.py:391: error: Cannot assign to a method  [assignment]
+ discord/gateway.py:391: error: Cannot assign to a method  [method-assign]
- discord/gateway.py:392: error: Cannot assign to a method  [assignment]
+ discord/gateway.py:392: error: Cannot assign to a method  [method-assign]
- discord/gateway.py:830: error: Cannot assign to a method  [assignment]
+ discord/gateway.py:830: error: Cannot assign to a method  [method-assign]
- discord/state.py:253: error: Cannot assign to a method  [assignment]
+ discord/state.py:253: error: Cannot assign to a method  [method-assign]
- discord/ui/view.py:175: error: Cannot assign to a method  [assignment]
+ discord/ui/view.py:175: error: Cannot assign to a method  [method-assign]
- discord/app_commands/tree.py:828: error: Cannot assign to a method  [assignment]
+ discord/app_commands/tree.py:828: error: Cannot assign to a method  [method-assign]
- discord/app_commands/commands.py:1807: error: Cannot assign to a method  [assignment]
+ discord/app_commands/commands.py:1807: error: Cannot assign to a method  [method-assign]
- discord/ext/commands/help.py:278: error: Cannot assign to a method  [assignment]
+ discord/ext/commands/help.py:278: error: Cannot assign to a method  [method-assign]
- discord/ext/commands/help.py:279: error: Cannot assign to a method  [assignment]
+ discord/ext/commands/help.py:279: error: Cannot assign to a method  [method-assign]
- discord/ext/tasks/__init__.py:289: error: Cannot assign to a method  [assignment]
+ discord/ext/tasks/__init__.py:289: error: Cannot assign to a method  [method-assign]

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/watcher/local_sources_watcher_test.py:297:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/watcher/local_sources_watcher_test.py:297:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/media_file_manager_test.py:152:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/media_file_manager_test.py:152:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/media_file_manager_test.py:191:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/media_file_manager_test.py:191:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/media_file_manager_test.py:300:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/media_file_manager_test.py:300:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/media_file_manager_test.py:321:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/media_file_manager_test.py:321:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/app_session_test.py:310:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/app_session_test.py:310:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/app_session_test.py:322:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/app_session_test.py:322:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/app_session_test.py:565:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/app_session_test.py:565:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/legacy_caching/hashing_test.py:68:5: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/legacy_caching/hashing_test.py:68:5: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:124:13: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:124:13: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:129:13: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:129:13: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:159:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:159:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:202:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:202:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:208:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:208:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:228:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:228:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:231:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/runtime/scriptrunner/script_runner_test.py:231:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/web/server/server_test.py:399:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/web/server/server_test.py:399:9: error: Cannot assign to a method  [method-assign]
- lib/tests/streamlit/web/server/server_test.py:442:9: error: Cannot assign to a method  [assignment]
+ lib/tests/streamlit/web/server/server_test.py:442:9: error: Cannot assign to a method  [method-assign]

@ilevkivskyi
Copy link
Member Author

@hauntsaninja @JukkaL any more comments on this one?

@hauntsaninja
Copy link
Collaborator

Looks good to me!

@ilevkivskyi ilevkivskyi merged commit 07f6721 into python:master Feb 5, 2023
@ilevkivskyi ilevkivskyi deleted the method-assign branch February 5, 2023 19:34
hauntsaninja added a commit that referenced this pull request Aug 10, 2023
Resolves #9789

Users could use `--disable-error-code=import-untyped` to only ignore
errors about libraries not having stubs, but continue to get errors
about e.g. typos in an import name.

The error subcode mechanism is new from #14570. Note that users will now
get a different error code depending on whether or not a package is
installed, and may not know that they can use the parent error code to
ignore the issue regardless. I think this is okay, in general type
checking results can change if you run them in two different
environments. Note also that with `--warn-unused-ignore` / `--strict`
mypy will complain about not having the most specific error code
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.

Unable to assign a function a method
4 participants