[Python-Dev] A Desperate Plea For Introspection (aka: BDFAP Needed) (original) (raw)

Yury Selivanov yselivanov.ml at gmail.com
Fri Jun 22 21:24:41 CEST 2012


On 2012-06-22, at 3:18 PM, Guido van Rossum wrote:

On Fri, Jun 22, 2012 at 12:10 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:

Guido,

On 2012-06-22, at 2:52 PM, Guido van Rossum wrote: ... 'empty' will also work. When python-dev collectively decided to go with missing attributes, 'empty' didn't yet exist (we added it with 'replace()' methods). If you think that using 'empty' is better, we can add that to the PEP. Yes, please do.

OK

(2) Could use an example on how to remove and add parameters using replace().

You have to build a new list of parameters and then pass it to 'replace()'. Example (from the actual signature() function implementation): if isinstance(obj, types.MethodType): # In this case we skip the first parameter of the underlying # function (usually self or cls). sig = signature(obj.func) return sig.replace(parameters=tuple(sig.parameters.values())[1:])

(3) You are using name(arg1, *, arg2) a lot. I think in most cases you mean for arg2 to be an optional keyword arg, but this notation doesn't convey that it is optional. Can you clarify? Yes, I meant optional. Would 'name(arg1, *, [arg2])' be better? Hardly, because that's not valid syntax. I'd write name(arg1, *, arg2=).

Like

replace(*, name=<default>, kind=<default>, default=<default>, 
                              annotation=<default>) -> Parameter

or

replace(*, name=<optional>, kind=<optional>, default=<optional>, 
                              annotation=<optional>) -> Parameter

(4) "If the object is a method" -- shouldn't that be "bound method"? (Unbound methods are undetectable.) Or is there some wider definition of method? What does it do for static or class methods?

Yes, it should be "If the object is a bound method". We'll fix this shortly. Great. classmethod as a descriptor returns a BoundMethod (bound to the class), staticmethod returns the original unmodified function, so both of them are supported automatically. Oh, great. IIRC it wasn't always like that. Maybe just add this to the PEP as a note?

OK. I'll clarify that.



More information about the Python-Dev mailing list