Any is excessively used as outer context for inference
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
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.
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.
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.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100