Skip to content

[ty] followup: add-import action for reveal_type too#21668

Merged
Gankra merged 3 commits intomainfrom
gankra/auto-imp2
Dec 8, 2025
Merged

[ty] followup: add-import action for reveal_type too#21668
Gankra merged 3 commits intomainfrom
gankra/auto-imp2

Conversation

@Gankra
Copy link
Contributor

@Gankra Gankra commented Nov 27, 2025

No description provided.

@Gankra Gankra added the ty Multi-file analysis & type inference label Nov 27, 2025
@Gankra Gankra added the server Related to the LSP server label Nov 27, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 27, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 27, 2025

mypy_primer results

No ecosystem changes detected ✅

No memory usage changes detected ✅

@AlexWaygood
Copy link
Member

This specific one probably could be added as a Fix, right? There's no extra computation required for us to figure out where we need to import it from, so it wouldn't slow down type-checking for it to be added as a Fix when we emit the diagnostic.

Also, it's possible we shouldn't suggest this autofix when the Python version is <3.11. It was only added to the typing module on Python 3.11 -- on earlier versions, you can import it from typing_extensions, but we don't know whether the user actually has that installed as a dependency or not. (According to typeshed, typing_extensions is part of the stdlib, but don't believe typeshed's lies -- that's just so that typeshed can use new typing features in the stdlib stubs ;)

@Gankra
Copy link
Contributor Author

Gankra commented Nov 27, 2025

Oh that's an interesting wrinkle, we absolutely constantly suggest importing stuff from typing_extensions 😬

@AlexWaygood
Copy link
Member

AlexWaygood commented Nov 27, 2025

can you use the resolve_module() option you added that ignores stub files to check whether there is actually a version of typing_extensions installed into site-packages before suggesting a typing_extensions import?

@Gankra
Copy link
Contributor Author

Gankra commented Nov 27, 2025

Filed:

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to exclude typing_extensions from our auto-import machinery for now, here. But I'd also be okay leaving as is, given that these are all still manual actions

if symbol.module.file(db) == Some(file) || symbol.module.is_known(db, KnownModule::Builtins)
{
continue;
}

I think I'd prefer making this a Fix on the reveal_type diagnostic as it then also becomes available on the CLI

Comment on lines 26 to 27
let lint_name = lint_id.name();
if lint_name == UNRESOLVED_REFERENCE.name() || lint_name == UNDEFINED_REVEAL.name() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let lint_name = lint_id.name();
if lint_name == UNRESOLVED_REFERENCE.name() || lint_name == UNDEFINED_REVEAL.name() {
if lint_id == LintId::of(&UNRESOLVED_REFERENCE) || lint_id == LintId::of(&UNDEFINED_REVEAL){

@Gankra
Copy link
Contributor Author

Gankra commented Nov 28, 2025

Thinking about it more, just because it's Almost Definitely typing.reveal_type doesn't actually mean it is? It feels a little dubious to refuse to check if their project has its own reveal_type

@MichaReiser
Copy link
Member

Thinking about it more, just because it's Almost Definitely typing.reveal_type doesn't actually mean it is? It feels a little dubious to refuse to check if their project has its own reveal_type

I think it's fine as an unsafe fix

@carljm carljm removed their request for review December 3, 2025 06:47
@Gankra
Copy link
Contributor Author

Gankra commented Dec 8, 2025

I keep getting annoyed that this doesn't work so I'm just going to land this and file followups.

@Gankra Gankra enabled auto-merge (squash) December 8, 2025 22:39
@Gankra Gankra merged commit 8ea1896 into main Dec 8, 2025
40 checks passed
@Gankra Gankra deleted the gankra/auto-imp2 branch December 8, 2025 22:44
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (29 commits)
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  [ty] Make Python-version subdiagnostics less verbose (#21849)
  [ty] Supress inlay hints when assigning a trivial initializer call (#21848)
  ...
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (31 commits)
  clippy
  reword comment
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  ...
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (31 commits)
  clippy
  reword comment
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  ...
dcreager added a commit that referenced this pull request Dec 10, 2025
* origin/main: (33 commits)
  [ty] Simplify union lower bounds and intersection upper bounds in constraint sets (#21871)
  [ty] Collapse `never` paths in constraint set BDDs (#21880)
  Fix leading comment formatting for lambdas with multiple parameters (#21879)
  [ty] Type inference for `@asynccontextmanager` (#21876)
  Fix comment placement in lambda parameters (#21868)
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants