On May 4, 2020, at 17:26, Steven D'Aprano <[email protected]> wrote:
>
> Proposal:
>
> We should have a mechanism that collects the current function or
> method's parameters into a dict, similar to the way locals() returns all
> local variables.
>
> This mechanism could be a new function,or it could even be a magic local
> variable inside each function, similar to what is done to make super()
> work. But for the sake of this discussion, I'll assume it is a function,
> `parameters()`, without worrying about whether it is a built-in or
> imported from the `inspect` module.
Some other popular languages have something pretty similar. (And they’re not
all as horrible as perl $*.) For example, in JavaScript, there’s a magic local
variable named arguments whose value is (a thing that duck-types as) a list of
the arguments passed to the current function’s parameters. (Not a dict, but
that’s just because JS doesn’t have keyword arguments.)
> function spam(x, y) { console.log(arguments) }
> spam(23, 42)
[23, 42]
Whether it’s called arguments or parameters, and whether it’s a magic variable
or a magic function, are minor bikeshedding issues (which you already raised),
not serious objections to considering them parallel. And I think all of the
other differences are either irrelevant, or obviously compelled by differences
between the languages (e.g., Python doesn’t need a rule for how it’s different
between the two different kinds of functions, because lambda doesn’t produce a
different kind of function).
So, I think this counts as a prior-art/cross-language argument for your
proposal.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/JABSTNZJ2D5GMI23FXJD7UAG7QPXVHJK/
Code of Conduct: http://python.org/psf/codeofconduct/