Re: proposal: Ellipsis in argument list
On Sat, Jan 12, 2013 at 5:30 AM, Szabolcs Blága <email@example.com>wrote:
> Dear All,
> I have an idea that the Ellipsis object could be used in function calls.
> The "..." syntax should automagically turn into an Ellipsis positional
> def f(*args):
> ext_args = 
> for i, a in enumerate(args):
> if a is Ellipsis:
> ext_args.extend([x for x in range(args[i-1]-1, args[i+1])])
> return ext_args
> Calling it for the above example specifically:
> >>>f(34, ..., 43)
> [34, 35, 36, 37, 38, 39, 40, 41, 42, 43]
> That might be useless or someone might say it is confusing, but I think it
> would be relatively easy to implement and a nice little syntactic "sugar"..
The basis for adding syntactic sugar is closer to: Is this something that
cannot be done clearly without the change, and is commonly useful?
Also, as Stefan showed, this is already valid syntax with differing
meaning, and thus could break existing code, making the threshold for
adding it even harder.
This change doesn't seem to useful, and can be easily done already:
Additionally, a decorator could easily be written to do this if you find
this is a pattern you commonly use for specific functions (untested), or
you can use your expansion function for other cases:
def newFunc(*args, **kwargs):
ext_args = 
for i, a in enumerate(args):
if a is Ellipsis:
ext_args.extend([x for x in range(args[i-1]-1, args[i+1])])
return func(*ext_args, **kwargs)
Then, you use this like:
> Best regards,
> Szabolcs Blaga
|All times are GMT. The time now is 10:45 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.