[Python-ideas] Inline Functions - idea
Steven D'Aprano
steve at pearwood.info
Thu Feb 6 11:56:02 CET 2014
On Wed, Feb 05, 2014 at 06:47:35PM -0800, Guido van Rossum wrote:
> On Wed, Feb 5, 2014 at 4:53 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> > class MyString(str):
> > def find(sub, start, end):
> > ...
> > # manipulate sub and/or start and/or end
> > ...
> > return super().find(#blah#)
> >
> > where #blah# means "pick out sub, start, and end from locals and use them".
> >
>
> And how on earth would the compiler know the argument names?
This is not a defence of the idea, which I find rather nasty, but I
suppose you might compile the call x.find(#blah#) into code like this:
# pseudo-code
func = getattr(x, 'find')
arg_list = inspect.getargspec(func).args
l = locals()
args = {arg: l[arg] for arg in arg_list if arg != "self"}
func(**args)
I think this idea would be inefficient, hard to understand, and brittle,
just to save the programmer from having to explicitly write out the
arguments to a function. I'm sure it would be really popular in PHP
circles :-)
--
Steven
More information about the Python-ideas
mailing list