python - What's the standard way to document a namedtuple? -


looking clean code using namedtuple hold multiple variables passing through number of functions. below simplified example (i have few more additional arguments).

before:

def my_function(session_cass, session_solr, session_mysql, some_var, another): """blah blah.  args:     session_cass (session): cassandra session execute queries with.     session_solr (solrconnection): solr connection execute requests with.     session_mysql (connection): mysql connection execute queries with.     some_var (str): yada yada.     (int): yada yada. """ 

after:

def my_function(sessions, some_var, another): """blah blah.  args:     sessions (namedtuple): holds database sessions.     some_var (str): yada yada.     (int): yada yada. """ 

for docstrings, i've been following google style guide, addition of types (inspired this post), because makes lot easier keep track of types coming in.

my question is, how go documenting namedtuple in scenario? it's set up, have no information types within namedtuple. there accepted way extend docstring here, or document namedtuple it's defined (not shown)?

i know document class in manor, i'm trying stay away using class don't have purpose other hold variables.

i not familiar google style guide, how this:

for namedtuple or tuple or list or whatever interchangeable go this

def my_function(sessions, some_var, another):     """blah blah.      args:         sessions (sequence): sequence of length n                               holds database sessions.                              in position 0 need bla bla                              in position 1 need ble ble                              ...                              in position n-1 need blu blu         some_var (str): yada yada.         (int): yada yada.     """     

on other hand if use attributes of namedtuple, maybe this

def my_function(sessions, some_var, another):     """blah blah.      args:         sessions (object): object holds database sessions.                            need following attributes                             bla_bla ...                            ble_ble ...                              ...                            blu_blu ...         some_var (str): yada yada.         (int): yada yada.     """     

for dictionary, how this

def my_function(sessions, some_var, another):     """blah blah.      args:         sessions (map): dictionary-like object holds                          database sessions, need following keys                         bla_bla ...                         ble_ble ...                            ...                         blu_blu ...         some_var (str): yada yada.         (int): yada yada.     """     

or

def my_function(sessions, some_var, another):     """blah blah.      args:         sessions (customclass): holds database sessions.         some_var (str): yada yada.         (int): yada yada.     """    

in each instance ask minimum functionality function need work correctly


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -