Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-11 Thread Paul Moore
Agreed. I was being lazy and didn't check precisely which exception was raised before writing the code. "Making this code production ready is left as an exercise for the reader" :-) On 11 October 2017 at 01:59, Steve D'Aprano wrote: > On Wed, 11 Oct 2017 02:15 am, Paul Moore wrote: > >> These are

Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Steve D'Aprano
On Wed, 11 Oct 2017 02:15 am, Paul Moore wrote: > These are all run-time behaviours, and so there's no way you can check > for them ahead of time. If you want to be sure setattr is allowed, you > need to handle possible exceptions: > > try: > setattr(o, name, value) > except Excep

Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Ned Batchelder
On 10/10/17 11:00 AM, Stefan Ram wrote: xieyuheng writes: 1. 'setattr(o, name, value)' can be used for what kind of objects ? It takes three objects as arguments. The first object should have an attribute named by the value of »name« that should allow this attribute to be set to »

Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Thomas Jollans
On 2017-10-10 16:37, xieyuheng wrote: >> Some callables may not be introspectable in certain implementations of > Python. >> For example, in CPython, some built-in functions defined in C >> provide no metadata about their arguments. > >this is depends on implementation, so I ask f

Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Terry Reedy
On 10/10/2017 10:37 AM, xieyuheng wrote: 2. what kind of functions does not have signature, so that 'inspect.signature(f)' can be used for them ? When .signature was added, it may not have been usable with *any* C-coded function. About the same, a mechanism was added to make signatures

Re: about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread Paul Moore
On 10 October 2017 at 15:37, xieyuheng wrote: > 1. 'setattr(o, name, value)' can be used for what kind of objects ? > >section '2. Built-in Functions' >of the official documentation says : > >> The function assigns the value to the attribute, provided the object > allows it. Anything

about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread xieyuheng
in CPython, instead of trying each object and function, is there any rules can help me answer the following questions ? or is there any third part documentations [community driven docs ? wiki ?] that can answer them ? 1. 'setattr(o, name, value)' can be used for what kind of objects ? secti

about 'setattr(o, name, value)' and 'inspect.signature(f)'

2017-10-10 Thread xieyuheng
in CPython, instead of trying each object and function, is there any rules can help me answer the following questions ? or is there any third part documentations [community driven docs ? wiki ?] that can answer them ? 1. 'setattr(o, name, value)' can be used for what kind of objects ? secti