Skip to content

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Apr 10, 2025

Summary

Similar to what we did for unresolved-reference and unresolved-attribute, we now also silence unresolved-import diagnostics if the corresponding import statement is unreachable.

This addresses the (already closed) issue #17049.

Test Plan

Adapted Markdown tests.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Apr 10, 2025
@sharkdp sharkdp force-pushed the david/unreachable-imports branch from 5ebe9a0 to 77da466 Compare April 10, 2025 15:44
@sharkdp sharkdp changed the title [red-knot] Silence unresolved-import in unreachable code [red-knot] Silence unresolved-import in unreachable code Apr 10, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 10, 2025

mypy_primer results

Changes were detected when running on open source projects
isort (https://github.com/pycqa/isort)
- error[lint:unresolved-import] /tmp/mypy_primer/projects/isort/isort/settings.py:52:16: Cannot resolve import `tomllib`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/isort/isort/settings.py:54:15: Cannot resolve import `._vendored`
- Found 59 diagnostics
+ Found 57 diagnostics

async-utils (https://github.com/mikeshardmind/async-utils)
- error[lint:unresolved-import] /tmp/mypy_primer/projects/async-utils/_misc/_ensure_annotations.py:57:16: Cannot resolve import `annotationlib`
- Found 31 diagnostics
+ Found 30 diagnostics

black (https://github.com/psf/black)
- error[lint:unresolved-import] /tmp/mypy_primer/projects/black/src/black/handle_ipynb_magics.py:14:24: Module `typing` has no member `TypeGuard`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/black/src/black/cache.py:20:24: Module `typing` has no member `Self`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/black/src/black/files.py:18:16: Cannot resolve import `tomllib`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/black/src/black/nodes.py:10:24: Module `typing` has no member `TypeGuard`
- Found 258 diagnostics
+ Found 254 diagnostics

rich (https://github.com/Textualize/rich)
- error[lint:unresolved-import] /tmp/mypy_primer/projects/rich/tests/test_syntax.py:26:10: Cannot resolve import `importlib_metadata`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/rich/docs/source/conf.py:27:10: Cannot resolve import `importlib_metadata`
- error[lint:unresolved-import] /tmp/mypy_primer/projects/rich/rich/progress.py:43:24: Module `typing` has no member `Self`
- Found 794 diagnostics
+ Found 791 diagnostics

@sharkdp sharkdp marked this pull request as ready for review April 10, 2025 15:49
@sharkdp sharkdp force-pushed the david/unreachable-imports branch from 77da466 to 537149f Compare April 10, 2025 15:49
@sharkdp sharkdp force-pushed the david/unreachable-imports branch from 537149f to c3a1b05 Compare April 10, 2025 19:05
@sharkdp sharkdp merged commit 8b2727c into main Apr 10, 2025
23 checks passed
@sharkdp sharkdp deleted the david/unreachable-imports branch April 10, 2025 19:13
dcreager added a commit that referenced this pull request Apr 10, 2025
* main: (30 commits)
  [red-knot] Silence `unresolved-import` in unreachable code (#17336)
  red_knot_python_semantic: move TODO comment
  red_knot_python_semantic: rename `lint()` and `report()`
  ruff_db: use `Annotation::get_message` in more places
  red_knot_python_semantic: tweak docs on building reporter builders
  red_knot_python_semantic: remove the "old" secondary message type
  red_knot_python_semantic: replace one use of "old" secondary diagnostic messages
  red_knot_python_semantic: update revealed type snapshots
  ruff_db: tweak how the revealed type diagnostic is rendered
  red_knot: add explicit test for concise `reveal_type` diagnostic
  red_knot_python_semantic: remove `InferContext::report_diagnostic`
  red_knot_python_semantic: add "reporter" API
  Bump 0.11.5 (#17337)
  [red-knot] Silence `unresolved-attribute` in unreachable code (#17305)
  Revert "[red-knot] Type narrowing for assertions (#17149)" (#17335)
  [red-knot] Type narrowing for assertions (#17149)
  [red-knot] avoid unnecessary evaluation of visibility constraint on definitely-unbound symbol (#17326)
  update cargo-dist (#17325)
  [red-knot] Fix double hovers/inlays in playground (#17334)
  [red-knot] Track reachability of scopes (#17332)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants