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

Match note error codes to import error codes #16004

Merged
merged 3 commits into from Sep 2, 2023

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Aug 31, 2023

Fixes #16003. Follow up to #14740

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

You'll need to update some ignores in mypy itself:

mypy/report.py:28: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
        from lxml import etree  # type: ignore[import]
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/test/testreports.py:10: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
        import lxml  # type: ignore[import]
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/test/testreports.py:25: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
            import lxml.etree as etree  # type: ignore[import]
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/test/testcmdline.py:[23](https://github.com/python/mypy/actions/runs/6031989547/job/16366518197?pr=16004#step:8:24): error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
        import lxml  # type: ignore[import]
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mypy/test/testcheck.py:29: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
        import lxml  # type: ignore[import]
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 5 errors in 4 files (checked [28](https://github.com/python/mypy/actions/runs/6031989547/job/16366518197?pr=16004#step:8:29)6 source files)

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

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

poetry (https://github.com/python-poetry/poetry)
+ src/poetry/installation/chef.py:16: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/tests/memory-leak-check.py:5: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ schema_salad/tests/memory-leak-check.py:6: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]

mypy (https://github.com/python/mypy)
+ mypy/report.py:28: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ mypy/test/testreports.py:10: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ mypy/test/testreports.py:25: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ mypy/test/testcmdline.py:23: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ mypy/test/testcheck.py:29: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]

jax (https://github.com/google/jax)
+ jax/_src/pickle_util.py:21: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ jax/experimental/jax2tf/examples/tf_js/quickdraw/quickdraw.py:33: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ jax/experimental/jax2tf/examples/serving/model_server_request.py:18: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ jax/experimental/jax2tf/examples/serving/model_server_request.py:30: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ jax/experimental/jax2tf/examples/serving/model_server_request.py:31: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ jax/experimental/jax2tf/examples/tflite/mnist/mnist.py:25: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]

spark (https://github.com/apache/spark)
+ python/pyspark/profiler.py:41: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ python/pyspark/accumulators.py:30: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ python/pyspark/pandas/sql_processor.py:18: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/http_writer.py:192: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ aiohttp/http_websocket.py:163: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ aiohttp/http_parser.py:918: error: Unused "type: ignore[import]" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
- aiohttp/pytest_plugin.py:23:1: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-import for more info

urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/request.py:24: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/util/request.py:26: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/util/request.py:32: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/response.py:19: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/response.py:21: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/response.py:26: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/contrib/socks.py:44: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ src/urllib3/contrib/pyopenssl.py:43: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ src/urllib3/contrib/pyopenssl.py:73: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]
+ test/__init__.py:21: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ test/__init__.py:23: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ test/__init__.py:28: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ test/contrib/test_socks.py:12: error: Unused "type: ignore" comment, use narrower [import-not-found] instead of [import] code  [unused-ignore]
+ test/contrib/test_pyopenssl.py:10: error: Unused "type: ignore" comment, use narrower [import-untyped] instead of [import] code  [unused-ignore]

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Aug 31, 2023

Note that the subcode logic is that we only the diagnostic about narrower error codes with --warn-unused-ignore and without --ignore-missing-imports. Note that mypy_primer forcefully enables --warn-unused-ignore.

If we want to reduce cost of this change, some options are:
a) provide a script to update the type ignores,
b) make the narrow check be part of ignore-without-code instead of --warn-unused-ignore,
c) use a subcode of unused-ignore for this case :-D

@hauntsaninja hauntsaninja merged commit 17e9e22 into python:master Sep 2, 2023
18 checks passed
@hauntsaninja hauntsaninja deleted the import-error-cod branch September 2, 2023 05:47
JukkaL pushed a commit that referenced this pull request Oct 10, 2023
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.

type: ignore[import-untyped] leaves a hard-to-suppress note
2 participants