Python Forum

Full Version: How to Print Function Prototype ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i want print function prototype. 

example
def foo(arg, kwarg = "py3.6", os = "Fedora"):
    pass

get_func_prototype(foo)

# output => '(arg, kwarg = "py3.6", os = "Fedora")'
Thanks.

sorry. I actually want to how to make same func prototype of other func prototype

example. (This is More important to me. I don't think there is no solution.)

def foo(script, lang = "Python", os = "Fedora"):
    pass

def bar( get_func_prototype(foo) ): # for same prototype with foo
    pass
That should be doable as well. Could you elaborate more on your use case? Like, are you just trying to wrap a function?
class myd( dict ):
    def __init__( get_func_prototype(dict.__init__)  ): # for the same prototype because i don't know what dict.__init__ prototype is. and i don't want to rewrite same prototype.
You're still talking too much implementation rather than goal. Is your goal to generate at runtime a class which shares a signature with a function? Are you trying not to duplicate code at write-time? Or do you just want to support dynamic calls to the class? If you just need to support calls, you don't need to do anything fancy, just use *args and **kwdwargs. Also, is dict important in your example? I can't make sense of it.
(May-10-2017, 08:10 PM)micseydel Wrote: [ -> ]You're still talking too much implementation rather than goal. Is your goal to generate at runtime a class which shares a signature with a function? Are you trying not to duplicate code at write-time? Or do you just want to support dynamic calls to the class? If you just need to support calls, you don't need to do anything fancy, just use *args and **kwdwargs. Also, is dict important in your example? I can't make sense of it.

sometimes we have to write same prototype many times. why does someone prefer long way rather than short way?

Edit:
Why do I use *args, **kwargs .Is this a right way for all funcs for all owerwriting ?
I'm not sure what you're writing that you're using the same function signature to the point where you don't want to keep writing it. I can't think of any solution, nor do I see this as a real problem. I don't think the *args or **kwargs will solve your problem (just shift the boiler plate).

I'd still like to see more context for what you're talking about. Like, if what you want those extra parameters for is just logging, then maybe a decorator would help.