coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
277 stars 24 forks source link

F811 redefinition of unused '__init__' from line 33 #76

Closed svaningelgem closed 1 year ago

svaningelgem commented 1 year ago
multimethod         1.5
Python              3.9.13
flake8              6.0.0
flake8-annotations  2.9.1
Flake8-pyproject    1.2.2

Hi,

I am trying to use multimethod in this way:

from dataclasses import dataclass

@dataclass
class FileSystemObjectInterface:
    fs: 'FileSystemInterface'
    path: str

    @multimethod
    def __init__(self, fs: 'FileSystemInterface', path: str) -> None:
        self.fs = fs
        self.path = path.rstrip(self.fs.path_separator)

    @multimethod
    def __init__(self, fs: 'FileSystemInterface', path: 'FileSystemObjectInterface') -> None:
        self.fs = fs
        self.path = path.__fspath__()

    @multimethod
    def __init__(self, path: 'FileSystemObjectInterface') -> None:
        self.fs = path.fs
        self.path = path.path

However, when running this through flake8 (with flake8-annotations installed), I'm getting the following error:

flake8 file_system.py --dispatch-decorators=multimethod

file_system.py:38:5: F811 redefinition of unused '__init__' from line 33
file_system.py:43:5: F811 redefinition of unused '__init__' from line 38

Is this something that should be resolved in this library, or is this something I should report to flake8-annotations? Not very sure... So I'm posting it here because it looks like flake8-annotations already has support for overloaded operators.

FYI, changing it into .register makes the fault go away:

    @multimethod
    def __init__(self, fs: 'FileSystemInterface', path: str) -> None:
        ...

    @__init__.register
    def _(self, fs: 'FileSystemInterface', path: 'FileSystemObjectInterface') -> None:
        ...

    @__init__.register
    def _(self, path: 'FileSystemObjectInterface') -> None:
        ...
coady commented 1 year ago

Thanks, yes this is a known issue. #12 discusses the same topic with mypy.

It can be suppressed with configuration, or use register. Static analyzers presumably just look for @overload textually.

coady commented 1 year ago

Closing as a duplicate of #12.