Thread: [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. |
From: <dva...@us...> - 2006-09-15 23:36:31
|
Revision: 1392 http://svn.sourceforge.net/epydoc/?rev=1392&view=rev Author: dvarrazzo Date: 2006-09-15 16:36:23 -0700 (Fri, 15 Sep 2006) Log Message: ----------- - Be more lenient about types specified before matching objects. 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 02:24:11 UTC (rev 1391) +++ branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py 2006-09-15 23:36:23 UTC (rev 1392) @@ -313,33 +313,44 @@ var = field fields.append(field) else: - warnings.append("there are more variables " - "named '%s'" % arg) + warnings.append( + "There is more than one variable 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) + warnings.append( + "There is more than one parameter 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) + if var is None and par is None: + # type before obj + tvar = tpar = field + else: + if var is not None and tvar is None: + tvar = field + if par is not None and tpar is None: + tpar = field else: # Unespected field fields.append(field) + # Put selected types into the proper output lists + if tvar is not None: + if var is not None: + fields.append(tvar) + else: + pass # [xx] warn about type w/o object? + + if tpar is not None: + if par is not None: + init_fields.append(tpar) + else: + pass # [xx] warn about type w/o object? + 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 @@ -754,15 +765,9 @@ def set_var_type(api_doc, ident, descr): if ident not in api_doc.variables: - # [xx] If there is a type w/o matching var, this would create - # a new var. The behavior is to be decied consistently also in other - # places in this sources (grep for [xx]). - # Currently disable the creation or else each "type" used in the - # class docstring to describe an __init__ parameter also generates - # an extra class variable. - #api_doc.variables[ident] = VariableDoc( - #container=api_doc, name=ident, - #canonical_name=api_doc.canonical_name+ident) + api_doc.variables[ident] = VariableDoc( + container=api_doc, name=ident, + canonical_name=api_doc.canonical_name+ident) return var_doc = api_doc.variables[ident] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dva...@us...> - 2006-09-16 00:20:11
|
Revision: 1394 http://svn.sourceforge.net/epydoc/?rev=1394&view=rev Author: dvarrazzo Date: 2006-09-15 17:20:06 -0700 (Fri, 15 Sep 2006) Log Message: ----------- - Reverting type fields handling to trunk behavior. 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-16 00:02:10 UTC (rev 1393) +++ branches/exp-args_in_class/epydoc/src/epydoc/docstringparser.py 2006-09-16 00:20:06 UTC (rev 1394) @@ -764,7 +764,6 @@ api_doc.variables[ident] = VariableDoc( container=api_doc, name=ident, canonical_name=api_doc.canonical_name+ident) - return var_doc = api_doc.variables[ident] if var_doc.type_descr not in (None, UNKNOWN): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |