[py-svn] r33653 - in py/dist/py/apigen: rest rest/testing tracer
fijal at codespeak.net
fijal at codespeak.net
Tue Oct 24 15:12:49 CEST 2006
Author: fijal
Date: Tue Oct 24 15:12:48 2006
New Revision: 33653
Modified:
py/dist/py/apigen/rest/genrest.py
py/dist/py/apigen/rest/testing/test_rest.py
py/dist/py/apigen/tracer/docstorage.py
Log:
Added cleaner arguments display.
Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py (original)
+++ py/dist/py/apigen/rest/genrest.py Tue Oct 24 15:12:48 2006
@@ -185,6 +185,13 @@
LiteralBlock(self.dsa.get_function_doc(fun_name)),
LiteralBlock(self.dsa.get_function_definition(fun_name))]
+
+ args, retval = self.dsa.get_function_signature(fun_name)
+ arg_str = "\n".join(["%s :: %s" % (str(name), str(type)) for name, type in args])
+ arg_str += "\n" + "Return value :: %s" % str(retval)
+ lst.append(Paragraph("where:"))
+ lst.append(LiteralBlock(arg_str))
+
# XXX missing implementation of dsa.get_function_location()
#filename, lineno = self.dsa.get_function_location(fun_name)
#linkname, linktarget = self.linkgen.getlink(filename, lineno)
@@ -195,15 +202,11 @@
lst.append(Paragraph('Function source:'))
lst.append(LiteralBlock(self.dsa.get_function_source(fun_name)))
- args, retval = self.dsa.get_function_signature(fun_name)
- # XXX: we just do "knowntype" here, but we should
- # present some more informative way, maybe even provide a link
- # for the type declaration (if this is known)
- arg_str = "(%s)" % (",".join([str(i) for i in args]))
- ret_str = str(retval)
- arg_quote = Paragraph("Function type:", Quote(arg_str), '->',
- Quote(ret_str))
- lst.append(arg_quote)
+ #arg_str = "(%s)" % (",".join([str(i) for i in args]))
+ #ret_str = str(retval)
+ #arg_quote = Paragraph("Function type:", Quote(arg_str), '->',
+ # Quote(ret_str))
+ #lst.append(arg_quote)
# call sites..
call_site_title = Title("Call sites:", belowchar='^')
Modified: py/dist/py/apigen/rest/testing/test_rest.py
==============================================================================
--- py/dist/py/apigen/rest/testing/test_rest.py (original)
+++ py/dist/py/apigen/rest/testing/test_rest.py Tue Oct 24 15:12:48 2006
@@ -237,3 +237,26 @@
r.write()
assert tempdir.join("function_blah.txt").open().read().find("a = 3") != -1
self.check_rest(tempdir)
+
+ def test_function_arguments(self):
+ def blah(a, b, c):
+ return "axx"
+
+ class C:
+ pass
+
+ descs = {'blah':blah}
+ ds = DocStorage().from_dict(descs)
+ t = Tracer(ds)
+ t.start_tracing()
+ blah(3, "x", C())
+ t.end_tracing()
+ lg = DirectPaste()
+ tempdir = temppath.ensure("function_args", dir=True)
+ r = RestGen(ds, lg, DirWriter(tempdir))
+ r.write()
+ source = tempdir.join("function_blah.txt").open().read()
+ assert source.find("a :: <Int>") != -1
+ assert source.find("b :: <String>") != -1
+ assert source.find("c :: <Instance>") != -1
+ self.check_rest(tempdir)
Modified: py/dist/py/apigen/tracer/docstorage.py
==============================================================================
--- py/dist/py/apigen/tracer/docstorage.py (original)
+++ py/dist/py/apigen/tracer/docstorage.py Tue Oct 24 15:12:48 2006
@@ -185,7 +185,10 @@
def get_function_signature(self, name):
desc = self.ds.descs[name]
- return desc.inputcells, desc.retval
+ # we return pairs of (name, type) here
+ names = desc.pyobj.func_code.co_varnames[:desc.pyobj.func_code.co_argcount]
+ types = desc.inputcells
+ return zip(names, types), desc.retval
def get_function_source(self, name):
desc = self.ds.descs[name]
More information about the py-svn
mailing list