Skip to content

Confusing error message for property with @overloaded function #8737

Open
@3rdcycle

Description

@3rdcycle

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions