[Epydoc-commits] SF.net SVN: epydoc: [1391] branches/exp-args_in_class/epydoc/src/epydoc/ docstring
Brought to you by:
edloper
|
From: <dva...@us...> - 2006-09-15 02:24:16
|
Revision: 1391
http://svn.sourceforge.net/epydoc/?rev=1391&view=rev
Author: dvarrazzo
Date: 2006-09-14 19:24:11 -0700 (Thu, 14 Sep 2006)
Log Message:
-----------
- Splitting argument refactored into a single distinct function.
Modified Paths:
--------------
branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py
Modified: branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py
===================================================================
--- branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py 2006-09-15 01:47:53 UTC (rev 1390)
+++ branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py 2006-09-15 02:24:11 UTC (rev 1391)
@@ -211,62 +211,8 @@
# docstring. This code assumes that a class docstring is parsed before
# the same class __init__ docstring.
if isinstance(api_doc, ClassDoc):
+ split_init_fields(fields, api_doc.init_args, field_warnings)
- # Split fields in lists according to their argument
- arg_fields = {}
- args_order = []
- i = 0
- while i < len(fields):
- field = fields[i]
-
- # gather together all the fields with the same arg
- if field.arg() is not None:
- arg_fields.setdefault(field.arg(), []).append(fields.pop(i))
- args_order.append(field.arg())
- else:
- i += 1
-
- # Now check that for each argument there is at most a single variable
- # and a single argument, and a single type for them.
- for arg in args_order:
- ff = arg_fields.pop(arg, None)
- if ff is None:
- continue
-
- var = tvar = par = tpar = None
- for field in ff:
- if field.tag() in VAR_TAGS:
- if var is None:
- var = field
- fields.append(field)
- else:
- field_warnings.append("there are more variables "
- "named '%s'" % arg)
- elif field.tag() in PARAM_TAGS:
- if par is None:
- par = field
- api_doc.init_args.append(field)
- else:
- field_warnings.append("there are more parameters "
- "named '%s'" % arg)
-
- elif field.tag() == 'type':
- gone = False
- if var is not None and tvar is None:
- tvar = field
- fields.append(field)
- gone = True
- if par is not None and tpar is None:
- tpar = field
- api_doc.init_args.append(field)
- gone = True
- if not gone:
- field_warnings.append("type for '%s' doesn't apply "
- "to any variable or argument" % arg)
-
- else: # Unespected field
- fields.append(field)
-
elif (isinstance(api_doc, RoutineDoc)
and api_doc.canonical_name[-1] == '__init__'):
class_doc = docindex.get_valdoc(api_doc.canonical_name[:-1])
@@ -332,6 +278,68 @@
if api_doc.sort_spec is UNKNOWN:
api_doc.sort_spec = []
+def split_init_fields(fields, init_fields, warnings):
+ """
+ Move the fields related to init into a different list.
+ C{fields} is supposed obtained from a class docstring. Remove
+ fields not related to the class from it and add them to C{init_fields},
+ which is a list of constructor fields.
+ """
+ # Split fields in lists according to their argument, keeping order.
+ arg_fields = {}
+ args_order = []
+ i = 0
+ while i < len(fields):
+ field = fields[i]
+
+ # gather together all the fields with the same arg
+ if field.arg() is not None:
+ arg_fields.setdefault(field.arg(), []).append(fields.pop(i))
+ args_order.append(field.arg())
+ else:
+ i += 1
+
+ # Now check that for each argument there is at most a single variable
+ # and a single parameter, and at most a single type for each of them.
+ for arg in args_order:
+ ff = arg_fields.pop(arg, None)
+ if ff is None:
+ continue
+
+ var = tvar = par = tpar = None
+ for field in ff:
+ if field.tag() in VAR_TAGS:
+ if var is None:
+ var = field
+ fields.append(field)
+ else:
+ warnings.append("there are more variables "
+ "named '%s'" % arg)
+ elif field.tag() in PARAM_TAGS:
+ if par is None:
+ par = field
+ init_fields.append(field)
+ else:
+ warnings.append("there are more parameters "
+ "named '%s'" % arg)
+
+ elif field.tag() == 'type':
+ gone = False
+ if var is not None and tvar is None:
+ tvar = field
+ fields.append(field)
+ gone = True
+ if par is not None and tpar is None:
+ tpar = field
+ init_fields.append(field)
+ gone = True
+ if not gone:
+ warnings.append("type for '%s' doesn't apply "
+ "to any variable or argument" % arg)
+
+ else: # Unespected field
+ fields.append(field)
+
def report_errors(api_doc, docindex, parse_errors, field_warnings):
"""A helper function for L{parse_docstring()} that reports any
markup warnings and field warnings that we encountered while
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|