Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to formally document a multipledispatch function? #107

Open
pw2wang opened this issue Dec 9, 2019 · 2 comments
Open

How to formally document a multipledispatch function? #107

pw2wang opened this issue Dec 9, 2019 · 2 comments

Comments

@pw2wang
Copy link

pw2wang commented Dec 9, 2019

I'm using the package to write my own multiple dispatch functions.
The functions work well, but I found it is hard to deal with the documentation.
When I want to use help() function to read the documentation, I found it is hard to let users understand the usage of this function.
Is it a way to make it readable for users?
Here is my example:

from multipledispatch import dispatch

@dispatch(int)
def f(x):
    '''
    function for int
    '''
    return "this is int"
    
@dispatch(str)
def f(x):
    '''
    function for string 
    '''
    return "this is string"

help(f)
@kenahoo
Copy link

kenahoo commented Mar 16, 2021

I came here to ask the same question, anyone figure out something that works well?

@kenahoo
Copy link

kenahoo commented Mar 17, 2021

I think this might work well - just write the documentation in one spot like so:

@dispatch(pd.DataFrame, pd.Series)
def foo(x, y) -> pd.DataFrame:
    ...implementation...

@dispatch(pd.DataFrame, pd.DataFrame)
def foo(x, y) -> pd.DataFrame:
    ...implementation...

foo.__doc__ = \
    """
    Docs go here
    """

Update: I guess that doesn't work, I get the exception AttributeError: can't set attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants