[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 2:34 PM Steven D'Aprano wrote: > > On Fri, Dec 03, 2021 at 10:40:42AM +1100, Chris Angelico wrote: > > > Here's what you get: > > > > >>> def f(lst=>[], n=>len(lst)): ... > > ... > > >>> f.__defaults_extra__ > > ('[]', 'len(lst)') > > > > String representation, but exactly w

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 2:52 PM Rob Cliffe via Python-ideas wrote: > > > > On 04/12/2021 01:06, Chris Angelico wrote: > > On Sat, Dec 4, 2021 at 11:59 AM Rob Cliffe via Python-ideas > > wrote: > >> > >> > >> On 03/12/2021 22:38, Chris Angelico wrote: > >>> On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 04/12/2021 01:06, Chris Angelico wrote: On Sat, Dec 4, 2021 at 11:59 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 22:38, Chris Angelico wrote: On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome surpri

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Steven D'Aprano
On Fri, Dec 03, 2021 at 10:40:42AM +1100, Chris Angelico wrote: > Here's what you get: > > >>> def f(lst=>[], n=>len(lst)): ... > ... > >>> f.__defaults_extra__ > ('[]', 'len(lst)') > > String representation, but exactly what the default is. Excellent. And you've just proven that we can evaluat

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Steven D'Aprano
On Thu, Dec 02, 2021 at 11:21:59AM -0800, Brendan Barnwell wrote: > As has happened often in these threads, it seems different people > mean different things by "default value". > > What you are calling "the default value" is "a thing that is used at > call time if no value is

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 11:59 AM Rob Cliffe via Python-ideas wrote: > > > > On 03/12/2021 22:38, Chris Angelico wrote: > > On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas > > wrote: > >> > >> > >> On 03/12/2021 19:32, Adam Johnson wrote: > >>> The first unwelcome surprise was: > >>> > >

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 03/12/2021 22:38, Chris Angelico wrote: On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome surprise was: >>> def func(a=>[]): ... return a ... >>> import inspect >>> inspect.s

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 6:33 AM Adam Johnson wrote: > > 5) Do you know how to compile CPython from source, and would you be > > willing to try this out? Please? :) > > I have. > > The first unwelcome surprise was: > > >>> def func(a=>[]): > ... return a > ... > > >>> import insp

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas wrote: > > > > On 03/12/2021 19:32, Adam Johnson wrote: > > > > The first unwelcome surprise was: > > > > >>> def func(a=>[]): > > ... return a > > ... > > > > >>> import inspect > > >>> inspect.signature(func)

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome surprise was: >>> def func(a=>[]): ... return a ... >>> import inspect >>> inspect.signature(func).parameters['a'].default Ellipsis Here the current behaviour of returning `Ellipsis` is very unfor

[Python-ideas] PEP 671 review of default arguments evaluation in other languages

2021-12-03 Thread Steven D'Aprano
A woefully incomplete review of default argument evaluation in other languages. Updates and corrections are welcome. Out of 22 languages apart from Python: - 3 use early binding (default is evaluated at compile or function definition time); - 12 use late binding (default is evaluated at call

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Adam Johnson
On Wed, 1 Dec 2021 at 06:19, Chris Angelico wrote: > > I've just updated PEP 671 https://www.python.org/dev/peps/pep-0671/ > with some additional information about the reference implementation, > and some clarifications elsewhere. > > *PEP 671: Syntax for late-bound function argument defaults* > >

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 4:48 AM Eric V. Smith wrote: > > On 12/2/2021 6:36 PM, Chris Angelico wrote: > > On Fri, Dec 3, 2021 at 7:54 AM Eric V. Smith wrote: > >> > >> Say I have a function with an early-bound default. I can inspect it and > >> I can change it. One reason to inspect it is so that I

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Eric V. Smith
On 12/2/2021 6:36 PM, Chris Angelico wrote: On Fri, Dec 3, 2021 at 7:54 AM Eric V. Smith wrote: Say I have a function with an early-bound default. I can inspect it and I can change it. One reason to inspect it is so that I can call the function with its default values. This is a form of wrappi

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Chris Angelico
On Sat, Dec 4, 2021 at 3:47 AM Andrew Jaffe wrote: > b) I think another motivation that hasn't been highlighted is teaching > -- perhaps surprisingly, I think adding this will make some aspects of > teaching *easier*. Mutable defaults are known to be confusing to Python > neophytes; I have certain

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Andrew Jaffe
On 01/12/2021 06:16, Chris Angelico wrote:> I've just updated PEP 671 https://www.python.org/dev/peps/pep-0671/ > with some additional information about the reference implementation, > and some clarifications elsewhere. > > *PEP 671: Syntax for late-bound function argument defaults* > > Questions

[Python-ideas] Re: PEP7 may need to add a info

2021-12-03 Thread Guido van Rossum
Good catch! You can submit a PR or issue to the peps project in the Python organization on GitHub. On Fri, Dec 3, 2021 at 00:24 wrote: > Hi! > When I read PEP7 and check Cpython source code, I found a deficiency that > in https://www.python.org/dev/peps/pep-0007/#code-lay-out. > In this section,

[Python-ideas] Re: Official means to release the GIL in Python

2021-12-03 Thread Barry
> On 3 Dec 2021, at 15:23, TobiasHT wrote: > > The GIL has been a widely discussed topic in the Python community. It's has > it's advantages and disadvantages. > I was suggesting that an official way be placed in the Python threading > module to release the GIL if one needs to perform some t

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Abe Dillon
"# or if you know what the default is: c = some_default if not cond: c = 42 func(a, b, c)" I would argue that, of the three examples; this one is the most problematic because it overly couples your code to an implementation detail of the function and makes it unnecessarily brittle to change. On t

[Python-ideas] Official means to release the GIL in Python

2021-12-03 Thread TobiasHT
The GIL has been a widely discussed topic in the Python community. It's has it's advantages and disadvantages. I was suggesting that an official way be placed in the Python threading module to release the GIL if one needs to perform some tasks that don't need the GIL. It could be something as si

[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-12-03 Thread Matsuoka Takuo
On Tue, 30 Nov 2021 at 04:55, Chris Angelico wrote: > > if this: > > 1 |> add(2) > > is exactly equivalent to this: > > add(1, 2) > > then neither the iterator nor the consumer needs to be aware of the > new protocol. > Along with such an operator form of functools.partial: ``` x |> f # equiva

[Python-ideas] PEP7 may need to add a info

2021-12-03 Thread zhouwenbonwpu
Hi! When I read PEP7 and check Cpython source code, I found a deficiency that in https://www.python.org/dev/peps/pep-0007/#code-lay-out. In this section, document said that ''' For external functions and variables, we always have a declaration in an appropriate header file in the "Include" direc

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Steven D'Aprano
On Fri, Dec 03, 2021 at 04:15:37PM +1100, Chris Angelico wrote: > So I don't think anyone is truly concerned about the pure "don't pass > the argument" case. The problem is the "maybe pass the argument" case. > That ends up looking like this: > > c = 42 > if cond: func(a, b) > else: func(a, b, c)