Tuesday, 15 June 2010

How to document structures in python? -



How to document structures in python? -

if argument function expected (or equivalent) structure, built using python's list, tuple , dict, how , where should documented?

an illustration documentation:

def foo(bar): """ args: bar: 2-tuple, ([(<mapping>,<number>), ...], <string>) """ pass

a bit cumbersome; problems:

the construction hard read hard indicate semantical meaning of each element of structure how indicate not-fix length should documented once, or everywhere edit: how show duck-typing ok element (ie. "dict" vs. "mapping-like")

edit: illustration not trying enforce types, it's trying document structure. point, duck typing ok.

my simple reply question quote zen of python: "explicit improve implicit". in terms of question, means write out in total what's needed, if takes entire paragraph document single argument. read python docs see examples. in specific case, can indicate duck-typing referring sequence rather tuple (see http://docs.python.org/2/library/collections.html#collections-abstract-base-classes).

python data-structures documentation docstring

No comments:

Post a Comment