[Python-Dev] pep 362 - 5th edition
Yury Selivanov
yselivanov.ml at gmail.com
Wed Jun 20 05:51:56 CEST 2012
On 2012-06-19, at 10:16 PM, Nick Coghlan wrote:
> On Wed, Jun 20, 2012 at 11:22 AM, Yury Selivanov
> <yselivanov.ml at gmail.com> wrote:
>> On 2012-06-19, at 8:39 PM, Nick Coghlan wrote:
>>> If we even keep that at all for the initial version of the API, the
>>> direct "default" and "annotation" attributes would just be read-only
>>> properties that accessed the "optional" container (reporting
>>> AttributeError if the corresponding attribute was missing)
>>
>> +0. I think that 'optional' is a bit unusual attribute for the stdlib,
>> but it will work if we make Signature immutable.
>
> The name isn't great, but the mapping is a lot more convenient when
> you need to handle the case of attributes potentially being missing.
What if instead of 'optional', we have 'base_signature'
(or 'from_signature')?
sig = signature(func)
params = OrderedDict(tuple(sig.parameters.items())[1:])
new_sig = Signature(params, base_signature=sig)
And for Paramater:
param = sig.parameters['foo']
param1 = Parameter('bar', base_parameter=param)
param2 = Parameter('spam', annotation=int, base_parameter=param)
param3 = Parameter(base_parameter=param)
param4 = Parameter(default=42, base_parameter=param)
So 'base_parameter' will be a template from which Parameter's constructor
will copy the missing arguments.
-
Yury
More information about the Python-Dev
mailing list