Michael Chermside wrote:
> Brett responds:
>> Yeah, I see what you are saying.  But I actually held this view long
>> before Iearned how Python did things underneath the covers.
>>
>> I have no clue how people tend to view things.  Anyone else care to
>> comment on how they tend to see arguments?
> 
> My mental model matches Brett's.

I think of them as separate things, too. Separate attributes also makes it 
easier to add additional metadata later, and the structure of each attribute 
can be well-defined.

For example, given:

def f(req:int, opt=val, *args, reqkwd, optkwd=val2, **kwds):
     pass

A signature object like the following would then be relatively easy to grasp:

sig = f.__signature__
assert sig.required_args == ('req',)
assert sig.optional_args == ('opt',)
assert sig.extra_args == 'args'
assert sig.required_keywords == ('reqkwd',)
assert sig.optional_keywords == ('optkwd',)
assert sig.extra_keywords == 'kwds'
assert sig.defaults == dict(opt=val, optkwd=val2)
assert sig.argtypes == dict(req=int)

Note that this can easily be adjusted for changes in signature expressiveness. 
Without keyword only arguments or argument type, the example might look like:

def f(req, opt=val, *args, **kwds):
     pass

sig = f.__signature__
assert sig.required_args == ('req',)
assert sig.optional_args == ('opt',)
assert sig.extra_args == 'args'
assert sig.extra_keywords == 'kwds'
assert sig.defaults == dict(opt=val, optkwd=val2)

The simplest example:

def f():
     pass

sig = f.__signature__
assert sig.required_args == ()
assert sig.optional_args == ()
assert sig.extra_args == ''
assert sig.extra_keywords == ''
assert sig.defaults == {}

A sequence+enum approach is really hard to adapt to changes in signature 
expressiveness, whereas an attribute based approach can just add more tuples 
and string-keyed dictionaries for all relevant information.

Cheers,
Nick.

-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to