coady / multimethod

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

flake8 reports redefinition when using multimethod #91

Closed firesurfer closed 1 year ago

firesurfer commented 1 year ago

Hi, I realized when linting python code - in my case with flake8. The linter reports redefintion warning.

Example code:

from multimethod import multimethod

@multimethod
def method(abc:str):
    print(abc)

@multimethod
def method(abc:str, x:int):
    print(abc, x)

method("hello")
method("hello", 10)

save it e.g. as test.py

flake8 test.py

gives the result ( I removed the non related outputs):


test.py:10:1: F811 redefinition of unused 'method' from line 5

``

Is there any know workaround/solution apart from ignoring F811 in certain files?
coady commented 1 year ago

You can ignore on individual lines.

def method(abc: str, x: int):  # noqa: F811

Or use the singledispatch-style register method after the first definition.

@method.register
def _(abc: str, x: int):
firesurfer commented 1 year ago

Thanks a lot. This is exactly what I was looking for.