Skip to content

Fix: no generic inlay hints for map filter for #1796#1797

Merged
DetachHead merged 4 commits into
DetachHead:mainfrom
nfer:fix/no-generic-inlay-hints-for-map-filter
May 11, 2026
Merged

Fix: no generic inlay hints for map filter for #1796#1797
DetachHead merged 4 commits into
DetachHead:mainfrom
nfer:fix/no-generic-inlay-hints-for-map-filter

Conversation

@nfer

@nfer nfer commented May 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

nfer added 2 commits May 9, 2026 17:08
Add `map(int, nums)` and `filter(int, nums)` cases to the `inlay_hints/generics.py` sample.

These calls reproduce the scenario from issue DetachHead#1796 where generic inlay hints can suggest invalid runtime syntax like `map[int](...)`.
  
Prevent generic inlay hints from being shown for builtins that are generic
in stubs but not subscriptable at runtime.

Specifically, skip generic inlay hint generation for `builtins.map` and
`builtins.filter` in `TypeInlayHintsWalker`. This avoids misleading hints
such as `map[int](...)` that can lead to runtime `TypeError`.

This addresses issue DetachHead#1796.

@DetachHead DetachHead left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thanks

Comment thread packages/pyright-internal/src/analyzer/typeInlayHintsWalker.ts Outdated
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

Comment thread packages/pyright-internal/src/analyzer/runtimeSubscriptability.ts Outdated
Comment thread packages/pyright-internal/src/analyzer/typeEvaluator.ts Outdated
@github-actions

This comment has been minimized.

Keep nonSubscriptableTypes in typeEvaluator.ts and expose isRuntimeSubscriptableClass on the TypeEvaluator interface.

Use evaluator.isRuntimeSubscriptableClass(...) in typeInlayHintsWalker and reuse the same function in typeEvaluator index diagnostics.
@nfer nfer force-pushed the fix/no-generic-inlay-hints-for-map-filter branch from ee4e989 to b0c3dc3 Compare May 10, 2026 05:32
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@DetachHead DetachHead merged commit 5e1f1fb into DetachHead:main May 11, 2026
13 checks passed
@nfer nfer deleted the fix/no-generic-inlay-hints-for-map-filter branch May 11, 2026 12:32
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.

Misleading generic inlay hints on built-ins like map and filter lead to runtime TypeError

2 participants