Menu

Support @return tag in generated docstring

2008-05-16
2013-03-15
  • Steffen Siebert

    Steffen Siebert - 2008-05-16

    Hi,

    would it be possible to include @return in the generated docstring for methods which return values?

    Ciao,
      Steffen

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2008-05-16

      Yes, it's possible (you can add it as a feature request -- or you could submit a patch -- take a look at org.python.pydev.editor.correctionassist.docstrings.AssistDocString.java ).

      Cheers,

      Fabio

       
      • Steffen Siebert

        Steffen Siebert - 2008-05-19

        Hi,

        I've looked into this class, but the problem is that I don't have any clue how to determine wether the current method returns a value or not. Can you give a hint where I should start searching?

        Ciao,
          Steffen

         
        • Fabio Zadrozny

          Fabio Zadrozny - 2008-05-20

          It should probably work something like:

          1. See where the scope of the current method ends. You can use org.python.pydev.parser.fastparser.FastParser#firstClassOrFunction to get where the next method / class starts -- the only catch is that you have to see the indent to see if it's not an inner function instead of a new scope.

          2. Iterate lines from the current line that starts the scope to the end of it searching for 'return'. You have to do some text analysis here -- an AST could be generated, but in this case it's probably not appropriate, especially if you want to be more error prone, as ASTs usually require the code to be parseable (or have some minor errors which can be treated)

          To iterate you can use the org.python.pydev.core.docutils.PyDocIterator (it helps skipping comments and literals)

          Cheers,

          Fabio

           
        • Fabio Zadrozny

          Fabio Zadrozny - 2008-05-20

          Actually, on a second thought, to know the scope of this method you should probably analyze the indentation -- and create a helper method that does that -- because sometimes the next scope starts only after some globals, so, that heuristic wouldn't work.

          Cheers,

          Fabio

           
MongoDB Logo MongoDB