SublimeAutoDocstring icon indicating copy to clipboard operation
SublimeAutoDocstring copied to clipboard

Modifying default for argument does not update the type in the docstring

Open Lightborne opened this issue 7 years ago • 2 comments

For example, write this in a new document:

def function(arg=None):
    pass

Then run any of the commands that updates the docstring, to get this:

def function(arg=None):
    """Summary
    
    Args:
        arg (None, optional): Description
    """
    pass

Now modify the default value of the argument, and rerun the command to update the docstring. It will not update with the new default value:

def function(arg=[]):
    """Summary
    
    Args:
        arg (None, optional): Description
    """
    pass

Note that arg still specifies a None type in the docstring, where it should be a list. This is what I believe the docstring should change to:

def function(arg=[]):
    """Summary
    
    Args:
        arg (list, optional): Description
    """
    pass

Lightborne avatar Feb 07 '18 19:02 Lightborne

This behavior is intentional. One of the tenets of this plugin is not to clobber text that the developer may have entered by hand. I couldn't think of a good way to detect whether or not text (type, description, etc.) has changed since the template was inserted. Imagine the case where arg starts as a list, but the developer wants the docstring to say "sequence" for the type. Later on, if the default value is changed to a tuple, it's likely that the developer would want the docstring to still say "sequence".

KristoforMaynard avatar Feb 07 '18 23:02 KristoforMaynard

Ahh, ok. I understand that.

I do have one idea. Perhaps you could advance the cursor to any "discrepancy" you may find. For example, running the AutoDocstring Current command on this snippet:

def function(arg=[]):
    """Summary
    
    Args:
        arg (None, optional): Description
    """
    pass

would move the cursor to (and select) the word "None", giving the user a visual queue that the plugin thinks there maybe a discrepancy there but it's up to the user to correct it. If there were multiple such discrepancies, the user could TAB through them.

Thanks for the explanation.

Lightborne avatar Feb 08 '18 01:02 Lightborne