problem with snippet def in python

Asked by Jorge

I have the following problem when defining a function in python:

I expand the snippet def and then move inside the parenthesis for the arguments. If my functions has arguments everything works
fine, but is the function has no arguments the documentation string gets "broken"...
Any ideas on how to proceed here?

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
SirVer (sirver) said :
#1

I have some trouble understanding your trouble. If I expand the def snippet and delete the arguments, I get this result:

def function():
    """@todo: Docstring for function """
    :returns: @todo
    """

    pass

What do you get, what do you expect?

Revision history for this message
Jorge (skeept) said :
#2

I get exactly the same as you, but I believe this is incorrect because of the first closing """"
what I would like to get is:

def function():
     """@todo: Docstring for function
     :returns: @todo
     """

    pass

What do you get, what do you expect?

Revision history for this message
Jorge (skeept) said :
#3

sorry I didn't meant to copy the last line.

Revision history for this message
SirVer (sirver) said :
#4

Ohh righty. DIdn't realize that this is wrong. I fixed this in r366. You can find it on launchpad or github.

Revision history for this message
Jorge (skeept) said :
#5

Thanks SirVer, that solved my question.

Revision history for this message
Jorge (skeept) said :
#6

I have another issue with the def snippet, this time when used in a class.
The problem is again when I don't want to use any arguments (so self will be the only argument).
When I try to delete arg1 with backspace instead of deleting arg1 when I keep pressing backspace
it just switches to normal mode, leaving the snippet as:

  def mymethod(self, ):
    """@todo: Docstring for mymethod

    :arg1: @todo
    :returns: @todo
    """

    pass

Let me know if you need clarification or if you don't have this issue.

Thanks!

Revision history for this message
SirVer (sirver) said :
#7

I also have the dangling self,

    def mymethod(self, ):

I will correct this soonish by only adding ', ' when there is really something in tabstop 2.

but I can't reproduce the exiting to normal mode. I tried def<tab><BS><c-j> and it jumped to the next snippet alright.

Revision history for this message
Jorge (skeept) said :
#8

First of all congratulations on release 2.

If I expand def in a class and If I delete the default argument I am having the same problem as
I inititially reported for the regular function, that is if I am in a class and expand def I get

  def function(self, arg1):
    """@todo: Docstring for function

    :arg1: @todo
    :returns: @todo
    """

    pass

if I move once and hit backspace when in arg1 the result is

  def function(self):
    """@todo: Docstring for function """
    :returns: @todo
    """

    pass

again here I believe there is an extra """".

The other minor thing with the def snippet is that if hit backspace with the default argument and after that
type "," again the following is what shows:

  def function(self, ,):
    """@todo: Docstring for function """
    :returns: @todo
    """

    pass

(it shows two consecutive commas)

Revision history for this message
SirVer (sirver) said :
#9

I cannot reproduce this. The def inside a class works fine for me

    def function(self):
        """@todo: Docstring for function
        :returns: @todo
        """

        pass

Could it be that you've overwritten the shipped snippet in our own configuration?

Also, the case with the two commas: just don't type a comma, start with an argument, the comma will appear automatically.

Can you help with this problem?

Provide an answer of your own, or ask Jorge for more information if necessary.

To post a message you must log in.