On Nov 14, 2007 10:30 AM, Isaac Morland <ijmorlan at cs.uwaterloo.ca> wrote: > For another project (see my previous email on named tuples), I needed to > represent procedure signatures, and use them to expand arguments into the > dictionary of values that exists when execution of a procedure starts. To my > surprise, this capability didn't seem to be provided by the Python library, > even though it clearly is present within the Python system somewhere. > > So I wrote a Signature class. Instances of the class represent all the > information present between the parentheses of a procedure definition. > Properties are provided to get the information out, and an expand_args method > can be called to expand arguments into a dictionary. This expand_args method > implements (if I've done it right) the argument conversion part of section > 5.3.4 of the Python Reference Manual (http://docs.python.org/ref/calls.html). > As Collin already pointed out, it sounds like you want PEP 362 to get into the stdlib. I have not made a big push to try to get my existing implementation into Python 2.6/3.0, but I plan to at some point. > I've put the code below, but I wonder if the real solution is just to create an > interface to already-existing capability? It occurs to me that the > implementation is likely to be in the interpreter itself and not written in > Python. > I don't see why a Python implementation is bad. If you make this information lazy then it is not such a big deal to have it take a little bit longer than if it was implemented in C. > One possible improvement (and I'm not sure it's better, so I'm just putting it > out there): perhaps expand_args should be renamed to __call__. Then essentially > a Signature object would be a procedure whose body is just "return locals ()". __call__ is already used a method name for objects that can be called. -Brett
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4