[Python-Dev] pep 362 - 5th edition (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Jun 20 06:55:54 CEST 2012
- Previous message: [Python-Dev] pep 362 - 5th edition
- Next message: [Python-Dev] pep 362 - 5th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Jun 20, 2012 at 1:51 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:
What if instead of 'optional', we have 'basesignature' (or 'fromsignature')?
sig = signature(func) params = OrderedDict(tuple(sig.parameters.items())[1:]) newsig = Signature(params, basesignature=sig) And for Paramater: param = sig.parameters['foo'] param1 = Parameter('bar', baseparameter=param) param2 = Parameter('spam', annotation=int, baseparameter=param) param3 = Parameter(baseparameter=param) param4 = Parameter(default=42, baseparameter=param) So 'baseparameter' will be a template from which Parameter's constructor will copy the missing arguments.
Good thought (and better than my initial idea), but I'd follow the model of namedtuple._replace and make it a separate instance method:
sig = signature(f)
new_sig = sig.replace(parameters=sig.parameters.values()[1:])
param = sig.parameters['foo']
param1 = param.replace(name='bar')
param2 = param.replace(name='spam', annotation=int)
param3 = param.replace() # namedtuple._replace also allows this edge case
param4 = param.replace(default=42)
Such a copy-and-override method should be the last piece needed to make immutable Signature objects a viable approach.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] pep 362 - 5th edition
- Next message: [Python-Dev] pep 362 - 5th edition
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]