[Python-3000] Generic function queries
ross at sourcelabs.com
Mon Nov 27 06:09:29 CET 2006
I've been reading the discussions on interfaces and generic functions with much interest. Some people have expressed concerns that readability and code discovery (where is the code that this call is going to run) may suffer. Could someone please address some simple questions for me about this as I'm not familiar with using generics in large projects?
For a reusable library of code that includes generics, does the library writer typically try to limit exception types that can pass out of the generic function? In other words, I guess what I'm asking is if there is way a for a library writer to register an "around" rule that would always be outermost so that one could wrap everything including later overrides in a try: except: or a transaction or something like that. If this is a *common* pattern would it be better handled by registering one or more context managers for the generic function? I haven't fully thought this out yet, but it seems like if context managers were useful for a suite of code using the "with" statement, that they could be just as applicable for managing the context of the suites of code reachable through the generic function dispatch. I leave syntax proposals for later if this is a useful idea, but some obvious ones come to mind.
I understand addmethod and hasmethod as have been proposed, but is there a need (for unit tests or other situations) to have a function that would return the concrete function object or list of function objects (if there is a chain) for a particular set of arguments without actually calling them (a getmethod or querymethod operation)?
If I had a generic function f, could I interactively do:
to begin discovering concrete functions associated with the generic, or there be a separate inspection mechanism?
What does help(f) do? I think Phillip said something about this, but I don't understand it from the usability aspect (i.e. Does help merge all docstrings from known implementations, provide the docstring of the default?)
More information about the Python-3000