Skip to content

@overloads on @abstractmethods shouldn't need an implementation #11488

@DetachHead

Description

@DetachHead
from abc import ABC, abstractmethod
from typing import overload


class Foo(ABC):
    @overload # error: An overloaded function outside a stub file must have an implementation
    @abstractmethod
    def foo(self, value: int) -> int:
        ...

    @overload
    @abstractmethod
    def foo(self, value: str) -> str:
        ...

    # (this fake impl shouldnt be necessary, that's the impl class's responsibility)
    # @abstractmethod
    # def foo(self, value: str | int) -> str | int:
    #     ...


class Bar(Foo):
    @overload
    def foo(self, value: int) -> int:
        ...

    @overload
    def foo(self, value: str) -> str:
        ...

    def foo(self, value: str | int) -> str | int:
        return 1

https://mypy-play.net/?mypy=latest&python=3.10&gist=9c19741f8c5682b5854d59f3cf5f9ade

the implementation on the abstract class serves no purpose and should not be required imo

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions