Any is excessively used as outer context for inference
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Reproduce the example with mypy and inspect how the Any outer context affects reveal_type([1]) in a **kwargs: Any call. Review the plugin re-inference APIs mentioned in the issue, including has_uninhabited_component() and ctx.api.accept(). Done means agreeing on and implementing a consistent inference behavior or public API, with regression coverage for the example and affected plugin scenarios.
Written by the indexing model from the issue text.
Description
Consider this example:
from typing import Any
def foo(**kwargs: Any) -> None: ...
foo(bar=reveal_type([1])) # Revealed type is List[Any]
Such behavior causes many false negatives for plugins that provide precise type checking for various ORMs, this includes SQLAlchemy plugin, our internal plugins, and likely Django plugin.
My guess this was added so that an empty list in Any context is inferred as List[Any] instead of List[<nothing>], but I think this is counterproductive. If empty collections cause issues for plugins they can easily work around using private APIs to re-infer argument type in generated precise context (for example using has_uninhabited_component() and ctx.api.accept()). Or maybe we can provide public API for inference.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100