Skip to content

Linter errors #111

Open
Open

Description

@srcolinas

Since the library works by defining the function multiple times, instead of using the same syntax of the singledispatch function, linters show ugly errors. Is there a way to avoid this?

For reference, here is how the singledispatch works:

@singledispatch
def fun(arg, verbose=False):
    if verbose:
        print("Let me just say,", end=" ")
    print(arg)

@fun.register(int)
def _(arg, verbose=False):
    if verbose:
        print("Strength in numbers, eh?", end=" ")
    print(arg)

@fun.register(list)
def _(arg, verbose=False):
    if verbose:
        print("Enumerate this:")
    for i, elem in enumerate(arg):
        print(i, elem)

Notice that there is no need to redefine two times the function fun and no name errors will be shown by linters.

(I now linters are not required anyway).

Activity

  1. mrocklin commented on Jul 18, 2020

    @mrocklin
    Owner

    It looks like this already works today

    In [1]: import multipledispatch                                                                                                                                                                                   
    
    In [2]: @multipledispatch.dispatch(object) 
       ...: def fun(arg, verbose=False): 
       ...:     if verbose: 
       ...:         print("Let me just say,", end=" ") 
       ...:     print(arg) 
       ...:  
       ...: @fun.register(int) 
       ...: def _(arg, verbose=False): 
       ...:     if verbose: 
       ...:         print("Strength in numbers, eh?", end=" ") 
       ...:     print(arg) 
       ...:  
       ...: @fun.register(list) 
       ...: def _(arg, verbose=False): 
       ...:     if verbose: 
       ...:         print("Enumerate this:") 
       ...:     for i, elem in enumerate(arg): 
       ...:         print(i, elem) 
       ...:                                                                                                                                                                                                           
    
    In [3]: fun("foo")                                                                                                                                                                                                
    foo
    
    In [4]: fun(1)                                                                                                                                                                                                    
    1
    
    In [5]: fun([1, 2, 3])                                                                                                                                                                                            
    0 1
    1 2
    2 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions