Confusing error message for property with @overloaded function
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
The following does not seem to work:
from typing import overload
class Example:
@overload
def fun(self, p: int) -> int: ...
@overload
def fun(self, p: str) -> str: ...
def fun(self, p=1):
if isinstance(p, int):
return 'foo'
else:
return 'bar'
prop = property(fun)
Argument 1 to "property" has incompatible type overloaded function; expected "Optional[Callable[[Any], Any]]"
Is this a bug or expected?
Also, fun(0) returns a string instead of an int as specified in the stub, but mypy doesn't seem to catch this. Again, bug or expected?
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 by reproducing the provided Python example and tracing the diagnostics for passing an overloaded method to property and for checking its implementation return type. Done means the expected behavior is established and the resulting diagnostics or checking behavior are covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100