Re: Modifying signature of ctor in class

2015-09-24 Thread gal kauffman
Sorry, you really can't give FunctionType an argument list. Maybe you can wrap the function with a callable object, this way you can change the argument list returned, and doest have to eval or compile code. On Sep 25, 2015 12:46 AM, "Joseph L. Casale" wrote: > > I don't think you can easily chan

Re: Modifying signature of ctor in class

2015-09-24 Thread gal kauffman
You can use the FunctionType class found in the types module (and its friends) to create functions on the run. And you can use the 'inspect' module to inspect existing functions, if you need to base the new function on an existing one. On Sep 24, 2015 11:28 PM, "Joseph L. Casale" wrote: > I have

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 5:01 PM, Joseph L. Casale wrote: >> py> from inspect import Signature, Parameter >> py> def foo(*args, **kwargs): pass >> ... >> py> foo.__signature__ = Signature([Parameter('x', >> Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', >> Parameter.KEYWORD_ONLY)]) >> py> help(fo

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]) > py> help(foo) > Help on function foo in module __main__: > > foo(x, *, y)

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 8:19 AM, Ian Kelly wrote: > Quick and dirty example: > > py> from inspect import Signature, Parameter > py> def foo(*args, **kwargs): pass > ... > py> foo.__signature__ = Signature([Parameter('x', > Parameter.POSITIONAL_OR_KEYWORD), Parameter('y', > Parameter.KEYWORD_ONLY)]

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 4:10 PM, Ian Kelly wrote: > On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale > wrote: >> I have a class factory where I dynamically add a constructor to the class >> output. >> The method is a closure and works just fine, however to accommodate the >> varied >> input it

Re: Modifying signature of ctor in class

2015-09-24 Thread Ian Kelly
On Thu, Sep 24, 2015 at 2:28 PM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class > output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc st

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 7:45 AM, Joseph L. Casale wrote: >> I don't think you can easily change the function's own definition, >> other than by using eval (or equivalent shenanigans, like crafting >> your own bytecode); but as of Python 3.something, the help() function >> looks for a __wrapped__ a

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> I don't think you can easily change the function's own definition, > other than by using eval (or equivalent shenanigans, like crafting > your own bytecode); but as of Python 3.something, the help() function > looks for a __wrapped__ attribute and will take function args from > that instead of th

Re: Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
> You can use the FunctionType class found in the types module (and its > friends) to create functions on the run. > And you can use the 'inspect' module to inspect existing functions, if you > need to base the new function on an existing one. Hi Gal, Seems the types module docs do not even have

Re: Modifying signature of ctor in class

2015-09-24 Thread Chris Angelico
On Fri, Sep 25, 2015 at 6:28 AM, Joseph L. Casale wrote: > I have a class factory where I dynamically add a constructor to the class > output. > The method is a closure and works just fine, however to accommodate the varied > input its signature is (*args, **kwargs). > > While I modify the doc st

Modifying signature of ctor in class

2015-09-24 Thread Joseph L. Casale
I have a class factory where I dynamically add a constructor to the class output. The method is a closure and works just fine, however to accommodate the varied input its signature is (*args, **kwargs). While I modify the doc strings, the ctor sig is not optimal. Without building this a string an