docstring

Can I document Python code with doxygen (and does it make sense)?

I like doxygen to create documentation of C or PHP code. I have an upcoming Python project and I think I remember that Python doesn't have /* .. */ comments and also has its own self-documentation facility which seems to be the pythonic way to document. Can I just use doxygen? Anything particular to be aware of? I have done some coding...

How to write meaningful docstrings?

Hello crowd, What, in Your opinion is a meaningful docstring? What do You expect to be described there? For example, consider this Python class's __init__: def __init__(self, name, value, displayName=None, matchingRule="strict"): """ name - field name value - field value displayName - nice display name, if empty will b...

Doctest for dynamically created objects.

What is the best way to test code like this (the one below obviously fails while object is created in different block every time): def get_session(db_name, verbose, test): """Returns current DB session from SQLAlchemy pool. >>> get_session('Mmusc20090126', False, True) <sqlalchemy.orm.session.Session object at 0xfb5ff0> """ if test: ...

Can I view the doc string of a function in Python using VIM?

Is there any way to view a function's doc string when writing Python in VIM? For instance: def MyFunction(spam): """A function that foobars the spam returns eggs""" return foobar(spam).eggs() I'd like to be able to type MyFunction(spam0) and see the doc string, either as a tooltip or in the status bar or any other way th...

Adding docstrings to namedtuples in Python?

Hello, Is it possible to add a documentation string to a namedtuple in an easy manner? I tried from collections import namedtuple Point = namedtuple("Point", ["x", "y"]) """ A point in 2D space """ # Yet another test """ A(nother) point in 2D space """ Point2 = namedtuple("Point2", ["x", "y"]) print Point.__doc__ # -> "Point(x, y)...

Commenting JavaScript functions á la Python Docstrings

It is valid JavaScript to write something like this: function example(x) { "Here is a short doc what I do."; // code of the function } The string actually does nothing. Is there any reason, why one shouldn't comment his/her functions in JavaScript in this way? Two points I could think of during wiriting the question: The st...

How should unit tests be documented?

I'm trying to improve the number and quality of tests in my Python projects. One of the the difficulties I've encountered as the number of tests increase is knowing what each test does and how it's supposed to help spot problems. I know that part of keeping track of tests is better unit test names (which has been addressed elsewhere), bu...

Python Decorator Problem with Docstrings

I have a problem using docstrings with decorators. Given the following example: def decorator(f): def _decorator(): print 'decorator active' f() return _decorator @decorator def foo(): '''the magic foo function''' print 'this is function foo' help(foo) Now the help doesn't show me the docstring of foo...

Are Python docstrings and comments stored in memory when module is loaded?

Are Python docstrings and comments stored in memory when module is loaded? I've wondered if this is true, because I usually document my code well; may this affect memory usage? Usually every Python object has a __doc__ method. Are those docstrings read from the file, or processed otherwise? I've done searches here in the forums, G...

Python: Why does this doc test fail?

This code that's in the doctest works when run by itself, but in this doctest it fails in 10 places. I can't figure out why it does though. The following is the entire module: class requireparams(object): """ >>> @requireparams(['name', 'pass', 'code']) >>> def complex_function(params): >>> print(params['name']) ...

More than 1 docstrings for a single module/function etc.?

I'm using python 3.1. Is it possible to create more than 1 docstring for a single module or function? I'm creating a program, and I'm intending to have multiple docstrings with a category for each. I intend to give other people the program so they can use it, and to make things easy for programmers and non-programmers alike, I'm putting...

How to spell check python docstring with emacs ?

I'd like to run a spell checker on the docstrings of my Python code, if possible from within emacs. I've found the ispell-check-comments setting which can be used to spell check only comments in code, but I was not able to target only the docstrings which are a fairly python-specific thing. ...

Replacing python docstrings

I have written a epytext to reST markup converter, and now I want to convert all the docstrings in my entire library from epytext to reST format. Is there a smart way to read the all the docstrings in a module and write back the replacements? ps: ast module perhaps? ...

Repetitive content in docstrings

What are good ways to deal with repetitive content in docstrings? I have many functions that take 'standard' arguments, which have to be explained in the docstring, but it would be nice to write the relevant parts of the docstring only once, as this would be much easier to maintain and update. I naively tried the following: arg_a = "a: ...

Python - do big doc strings waste memory?

I understand that in Python a string is simply an expression and a string by itself would be garbage collected immediately upon return of control to a code's caller, but... Large class/method doc strings in your code: do they waste memory by building the string objects up? Module level doc strings: are they stored infinitely by the int...

documenting class attributes

I'm writing a lightweight class whose attributes are intended to be publicly accessible, and only sometimes overridden in specific instantiations. There's no provision in the Python language for creating docstrings for class attributes, or any sort of attributes, for that matter. What is the accepted way, should there be one, to docume...

Java docstringes through private variable in class

public static class cls{ private String text; public String getText(){ return text; } } Is it possible to show the text variable in the docstrings of of cls in Java without having to copypaste the content? ...

Python solution for creating documentation from source files

Hi, I have lots of Python (2.x) source files in a quite large project. Most of them is quite well documented - in docstrings, or comments at the beginning of classes/methods. What I look for is a tool that would read those files and create a documentation out of it - best would be with class inheritance, method names and arguments and...

about python __doc__ docstring

i want to show docstring of my function, but if i use like this @cost_time def func(): "define ...." blabla print func.__doc__ it will not show the docstring,just because i use some meta programming tricky, how can fix this? ...

How can I make Python/Sphinx document object attributes only declared in __init__?

I have Python classes with object attributes which are only declared as part of running the constructor, like so: class Foo(object): def __init__(self, base): self.basepath = base temp = [] for run in os.listdir(self.basepath): if self.foo(run): temp.append(run) self.avail...