Don't report "expression contains 'Any'" if it's a `TypeOfAny.from_error`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Update
@A5Rocks idea about not reporting expression contains Any if it's TypeOfAny.from_error is based 100. I also realized that if it's <nothing> it would still complain about attribute access etc being incorrect.
Bug Report
The reason being that when you update an overloaded signature you can get hundreds of reported "Expression contains 'Any'" errors, when there are in reality an order of magnitude less actual errors.
from typing import overload
@overload
def foo(a: int) -> int: ...
# this overload was just removed
# @overload
# def foo(a: None) -> str ...
@overload
def foo(a: str) -> str: ...
def foo(a: object) -> object: ...
a = foo(None) # error: No overload variant of "foo" matches argument type "None"\
# error: Expression has type "Any"
reveal_type(a) # error: Expression has type "Any"\
# note: Revealed type is "Any"
print(a) # error: Expression has type "Any"
bar(a) # error: Expression has type "Any"
a + "asdf" # error: Expression has type "Any"
But If TypeOfAny.from_errors are ignored:
a = foo(None) # error: No overload variant of "foo" matches argument type "None"
reveal_type(a) # note: Revealed type is "Any"
print(a)
bar(a)
a + "asdf"
Original Title
Invocations of overloaded functions with invalid argument types shouldn't return Any it should return <nothing>
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
Start with the minimal overloaded-call examples in the issue and trace how invalid overload resolution assigns TypeOfAny.from_error and how later expressions report that type. Done means the original overload error remains, while propagated error Any values do not produce additional "Expression has type Any" diagnostics; the issue names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100