[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 329. I did not know
that you could have sequence unpacking in
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Feb 26 10:05:12 EST 2005
Log message for revision 29311:
Fixed issue 329. I did not know that you could have sequence unpacking in
arguments as well. This is definitely one of the stranger Python features,
but probably feels natural to others. ;-)
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/doc/TODO.txt
U Zope3/trunk/src/zope/app/apidoc/utilities.py
U Zope3/trunk/src/zope/app/apidoc/utilities.txt
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-02-26 15:03:58 UTC (rev 29310)
+++ Zope3/trunk/doc/CHANGES.txt 2005-02-26 15:05:12 UTC (rev 29311)
@@ -461,6 +461,8 @@
Bug Fixes
+ - Fixed issue #329 (apidoc + TAL)
+
- Object copy events weren't dispatched for object sublocations.
- When I converted layers and skins to interfaces, I got the layer part
Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt 2005-02-26 15:03:58 UTC (rev 29310)
+++ Zope3/trunk/doc/TODO.txt 2005-02-26 15:05:12 UTC (rev 29311)
@@ -71,8 +71,6 @@
* 321: TravelsalError after renaming or moving Sites with local services
* 323: Permission zope.Public in addfrom does not work
-
-* 329: apidoc + TAL (Stephan)
Bugs starting with * represent bugs that must be fixed for the 3.0.x branch as
Modified: Zope3/trunk/src/zope/app/apidoc/utilities.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/utilities.py 2005-02-26 15:03:58 UTC (rev 29310)
+++ Zope3/trunk/src/zope/app/apidoc/utilities.py 2005-02-26 15:05:12 UTC (rev 29311)
@@ -128,27 +128,34 @@
if not isinstance(func, (types.FunctionType, types.MethodType)):
raise TypeError("func must be a function or method")
- args, varargs, varkw, default = inspect.getargspec(func)
+ args, varargs, varkw, defaults = inspect.getargspec(func)
placeholder = object()
sig = '('
# By filling up the default tuple, we now have equal indeces for args and
# default.
- if default is not None:
- default = (placeholder,)*(len(args)-len(default)) + default
+ if defaults is not None:
+ defaults = (placeholder,)*(len(args)-len(defaults)) + defaults
else:
- default = (placeholder,)*len(args)
+ defaults = (placeholder,)*len(args)
str_args = []
- for i in range(len(args)):
+ for name, default in zip(args, defaults):
# Neglect self, since it is always there and not part of the signature.
# This way the implementation and interface signatures should match.
- if args[i] == 'self' and type(func) == types.MethodType:
+ if name == 'self' and type(func) == types.MethodType:
continue
- if default[i] is placeholder:
- str_args.append(args[i])
+
+ # Make sure the name is a string
+ if isinstance(name, (tuple, list)):
+ name = '(' + ', '.join(name) + ')'
+ elif not isinstance(name, str):
+ name = repr(name)
+
+ if default is placeholder:
+ str_args.append(name)
else:
- str_args.append(args[i] + '=' + repr(default[i]))
+ str_args.append(name + '=' + repr(default))
if varargs:
str_args.append('*'+varargs)
Modified: Zope3/trunk/src/zope/app/apidoc/utilities.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/utilities.txt 2005-02-26 15:03:58 UTC (rev 29310)
+++ Zope3/trunk/src/zope/app/apidoc/utilities.txt 2005-02-26 15:05:12 UTC (rev 29311)
@@ -324,6 +324,38 @@
...
TypeError: func must be a function or method
+A very uncommon, but perfectly valid, case is that tuple arguments are
+unpacked inside the argument list of the function. Here is an example:
+
+ >>> def func((arg1, arg2)):
+ ... pass
+ >>> utilities.getFunctionSignature(func)
+ '((arg1, arg2))'
+
+Even default assignment is allowed:
+
+ >>> def func((arg1, arg2)=(1, 2)):
+ ... pass
+ >>> utilities.getFunctionSignature(func)
+ '((arg1, arg2)=(1, 2))'
+
+However, lists of this type are not allowed inside the argument list:
+
+ >>> def func([arg1, arg2]):
+ ... pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: invalid syntax
+
+Internal assignment is also not legal:
+
+ >>> def func((arg1, arg2=1)):
+ ... pass
+ Traceback (most recent call last):
+ ...
+ SyntaxError: invalid syntax
+
+
`getPublicAttributes(obj)`
--------------------------
More information about the Zope3-Checkins
mailing list