Spun off from PEP 505 thread on python-dev.
One of the weaker use-cases for None-coalescing is function default
arguments, where the technical default is None but the function wants
to use some other value instead. This is a weak argument in favour of
None-coalescing because only a small set of su
On 10/23/21 9:07 AM, Chris Angelico wrote:
> Proposal: Proper syntax and support for late-bound argument defaults.
I like the proposal.
> def spaminate(thing, count=:thing.getdefault()):
> ...
>
> def bisect(a, x, lo=0, hi=:len(a)):
> if lo < 0:
> raise ValueError('lo must be
On Sun, Oct 24, 2021 at 3:26 AM Ethan Furman wrote:
>
> On 10/23/21 9:07 AM, Chris Angelico wrote:
>
> > Proposal: Proper syntax and support for late-bound argument defaults.
>
> I like the proposal.
>
> > def spaminate(thing, count=:thing.getdefault()):
> > ...
> >
> > def bisect(a, x,
Hello people,
I was thinking of a "def" statement in Python.
Its really weird that it can define only method, since it means "define".
It shouldn't be hard to detect if this is a variable or a method, because
method needs "()" to have arguments(even if there are zero of them),
and defining varia
On 10/23/21 9:44 AM, Chris Angelico wrote:
> Feel free to propose an improvement to the syntax. Whatever spelling
> is ultimately used, this would still be of value.
def bisect(a, x, lo=0, hi?=len(a)):
--
~Ethan~
___
Python-ideas mailing list -- p
Why would anyone want to type:
def variable = value
when they could just type:
variable = value
instead? Perhaps if I was being paid by the character typed...
def my__really__good__variable = ( value )# Assign value to
my__really__good__variable.
*wink*
But all joking
>From my phone.
An important thing about def x and class A is that the strings x and A are
made available to the constructor for x and A respectively. The same is not
true for x=val.
Jonathan
___
Python-ideas mailing list -- python-ideas@python.org
To u
On Sun, Oct 24, 2021 at 4:12 AM Ethan Furman wrote:
>
> On 10/23/21 9:44 AM, Chris Angelico wrote:
>
> > Feel free to propose an improvement to the syntax. Whatever spelling
> > is ultimately used, this would still be of value.
>
> def bisect(a, x, lo=0, hi?=len(a)):
>
Ah, okay. I had cons
On 2021-10-24 at 03:07:45 +1100,
Chris Angelico wrote:
> def bisect(a, x, lo=0, hi=None):
> if lo < 0:
> raise ValueError('lo must be non-negative')
> if hi is None:
> hi = len(a)
>
> It's clear what value lo gets if you omit it. It's less clear what hi
> gets. And the si
I like that you're trying to fix this wart! I think that using a different
syntax may be the only way out. My own bikeshed color to try would be `=>`,
assuming we'll introduce `(x) => x+1` as the new lambda syntax, but I can
see problems with both as well :-).
--
--Guido van Rossum (python.org/~g
On Sun, Oct 24, 2021 at 6:18 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:
> > The expression would be evaluated in the function's context, having
> > available to it everything that the function has. Notably, this is NOT
> > the same as the context of the function definition, but this is only
> >
On Sat, 23 Oct 2021 at 17:09, Chris Angelico wrote:
>
> Proposal: Proper syntax and support for late-bound argument defaults.
>
> def spaminate(thing, count=:thing.getdefault()):
> ...
>
> def bisect(a, x, lo=0, hi=:len(a)):
> if lo < 0:
> raise ValueError('lo must be non-negative'
On Sat, Oct 23, 2021 at 12:56 PM Guido van Rossum wrote:
> I like that you're trying to fix this wart! I think that using a different
> syntax may be the only way out. My own bikeshed color to try would be `=>`,
> assuming we'll introduce `(x) => x+1` as the new lambda syntax, but I can
> see pro
On Sun, Oct 24, 2021 at 6:55 AM Guido van Rossum wrote:
>
> I like that you're trying to fix this wart! I think that using a different
> syntax may be the only way out. My own bikeshed color to try would be `=>`,
> assuming we'll introduce `(x) => x+1` as the new lambda syntax, but I can see
>
On Sun, Oct 24, 2021 at 7:58 AM Bruce Leban wrote:
>
> On Sat, Oct 23, 2021 at 12:56 PM Guido van Rossum wrote:
>>
>> I like that you're trying to fix this wart! I think that using a different
>> syntax may be the only way out. My own bikeshed color to try would be `=>`,
>> assuming we'll intro
On 2021-10-24 at 06:54:36 +1100,
Chris Angelico wrote:
> On Sun, Oct 24, 2021 at 6:18 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:
> > > The expression would be evaluated in the function's context, having
> > > available to it everything that the function has. Notably, this is NOT
> > > the sam
On 10/23/21 2:23 PM, Chris Angelico wrote:
> It seems like there's broad interest in this, but a lot of details to
> nut out. I think it may be time for me to write up a full PEP. Guido,
> if I'm understanding recent SC decisions correctly, a PEP editor can
> self-sponsor, correct?
Of all people
On Sun, Oct 24, 2021 at 8:56 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2021-10-24 at 06:54:36 +1100,
> Chris Angelico wrote:
>
> > On Sun, Oct 24, 2021 at 6:18 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:
> > > > The expression would be evaluated in the function's context, having
> >
On Sun, Oct 24, 2021 at 9:05 AM Ethan Furman wrote:
>
> On 10/23/21 2:23 PM, Chris Angelico wrote:
>
> > It seems like there's broad interest in this, but a lot of details to
> > nut out. I think it may be time for me to write up a full PEP. Guido,
> > if I'm understanding recent SC decisions c
Incorporates comments from the thread we just had.
Is anyone interested in coauthoring this with me? Anyone who has
strong interest in seeing this happen - whether you've been around the
Python lists for years, or you're new and interested in getting
involved for the first time, or anywhere in bet
Eight hours from the initial post on Python-Ideas, to a PEP, with just
eight responses from six people. Is that some sort of a record?
And in the wee hours of the morning too (3am to 11am local time). I
thought my sleep habits were bad. Do you not sleep any more? :-)
--
Steve
El sáb, 23 oct 2021 a las 12:57, Guido van Rossum ()
escribió:
> I like that you're trying to fix this wart! I think that using a different
> syntax may be the only way out. My own bikeshed color to try would be `=>`,
> assuming we'll introduce `(x) => x+1` as the new lambda syntax, but I can
> se
On Sun, Oct 24, 2021 at 12:10 PM Steven D'Aprano wrote:
>
> Eight hours from the initial post on Python-Ideas, to a PEP, with just
> eight responses from six people. Is that some sort of a record?
>
> And in the wee hours of the morning too (3am to 11am local time). I
> thought my sleep habits wer
>From what I've seen so far, I'm -0 on this.
I understand the pattern it addresses, but it doesn't feel all that common,
nor that hard to address with the existing sentinel-check pattern alien in
the PEP draft.
This just doesn't feel big enough to merit it's own syntax.
... On the other hand, if
On Sun, Oct 24, 2021 at 06:54:36AM +1100, Chris Angelico wrote:
[...]
> Teaching moment. Currently, the equivalent second function would be this:
>
> def f2(l=None):
> if l is None: l = []
> l.append(4)
> return l
>
> And the whole "early bind or late bind" question is there just the
On Sun, Oct 24, 2021 at 12:44 PM Rob Cliffe wrote:
> I'm not keen on the
> var = > expr
> syntax. IMO the arrow is pointing the wrong way. expr is assigned to var.
That's definitely open to discussion.
> Some possible alternatives, if there is no technical reason they
> wouldn't work (as
This might be a dumb question but is the context built only left to right?
Or will this be legal?
def f(a, *, b=:c, c=:b):
print(f"{a=} {b=} {c=}")
>>> f(1, b=2)
a=1 b=2 c=2
>>> f(1, c=2)
a=1 b=2 c=2
___
Python-ideas mailing list -- python-ideas@py
On Sun, Oct 24, 2021 at 1:00 PM Steven D'Aprano wrote:
>
> On Sun, Oct 24, 2021 at 06:54:36AM +1100, Chris Angelico wrote:
>
> [...]
> > Teaching moment. Currently, the equivalent second function would be this:
> >
> > def f2(l=None):
> > if l is None: l = []
> > l.append(4)
> > return
On Sun, Oct 24, 2021 at 1:12 PM Ricky Teachey wrote:
>
> This might be a dumb question but is the context built only left to right? Or
> will this be legal?
>
> def f(a, *, b=:c, c=:b):
> print(f"{a=} {b=} {c=}")
>
> >>> f(1, b=2)
> a=1 b=2 c=2
>
> >>> f(1, c=2)
> a=1 b=2 c=2
>
That's someth
On Sat, Oct 23, 2021 at 02:54:54PM -0700, 2qdxy4rzwzuui...@potatochowder.com
wrote:
[...]
> > The function header is a syntactic construct - the "def" line, any
> > decorators, annotations, etc.
>
> If you mean that def statements and decorators run at compile time, then
> I agree. If you mean
Love the proposed syntax, it's clear and visible without being verbose. I was a
bit worried with the "=:" syntax as, at first glance, it can be easily mistaken
with a regular "=" but you can't miss "=>". Also, I think the syntax fits
really well with the meaning of the operator, which is importa
On Sat, Oct 23, 2021 at 6:23 PM Jelle Zijlstra
wrote:
> In the PEP's example:
>
> def bisect_right(a, x, lo=0, hi=>len(a), *, key=None):
>
> This reads to me like we're putting "hi" into "len(a)", when it's in fact
> the reverse.
>
I think in most cases what's on the right side will be something
On Sun, Oct 24, 2021 at 1:48 PM Bruce Leban wrote:
>
>
> On Sat, Oct 23, 2021 at 6:23 PM Jelle Zijlstra
> wrote:
>>
>> In the PEP's example:
>>
>> def bisect_right(a, x, lo=0, hi=>len(a), *, key=None):
>>
>> This reads to me like we're putting "hi" into "len(a)", when it's in fact
>> the revers
On Sun, Oct 24, 2021 at 01:16:02PM +1100, Chris Angelico wrote:
> What I'm more often seeing is cases that are less obviously a
> late-binding, but where the sentinel is replaced with the "real" value
> at the point where it's used, rather than up the top of the function.
Got any examples you can
On Sat, Oct 23, 2021 at 7:00 PM Steven D'Aprano wrote:
> I challenge that assertion. I've never knowingly seen a function where
> the late binding is "buried deeper in the function", certainly not deep
> enough that it is not obvious. It is a very strong convention that such
> late binding operat
On Sun, Oct 24, 2021 at 05:49:50AM +0400, David Mertz, Ph.D. wrote:
> ... On the other hand, if this could express a much more general deferred
> computation, I'd be really enthusiastic (subject to syntax and behavioral
> details).
>
> However, I recognize that a new general "dynamically scoped l
--- Bruce
On Sat, Oct 23, 2021 at 7:55 PM Chris Angelico wrote:
> On Sun, Oct 24, 2021 at 1:48 PM Bruce Leban wrote:
> >
> >
> > On Sat, Oct 23, 2021 at 6:23 PM Jelle Zijlstra
> wrote:
> >>
> >> In the PEP's example:
> >>
> >> def bisect_right(a, x, lo=0, hi=>len(a), *, key=None):
> >>
> >>
On Sat, Oct 23, 2021 at 7:55 PM Steven D'Aprano wrote:
>
> And is it really a problem if we delay the late-binding to the point
> where the value is actually needed? ...
[in that csse] I would stick to manual late-
> binding using None, and only evaluate it as needed.
>
> Maybe this i
On Sun, Oct 24, 2021 at 1:53 PM Steven D'Aprano wrote:
>
> On Sun, Oct 24, 2021 at 01:16:02PM +1100, Chris Angelico wrote:
>
> > What I'm more often seeing is cases that are less obviously a
> > late-binding, but where the sentinel is replaced with the "real" value
> > at the point where it's used
On Sat, Oct 23, 2021, 10:58 PM Steven D'Aprano
> > ... On the other hand, if this could express a much more general
> deferred computation, I'd be really enthusiastic (subject to syntax and
> behavioral details).
> >
> > However, I recognize that a new general "dynamically scoped lambda"
> would i
On Sun, Oct 24, 2021 at 2:21 PM David Mertz, Ph.D.
wrote:
>
> On Sat, Oct 23, 2021, 10:58 PM Steven D'Aprano
>>
>> > ... On the other hand, if this could express a much more general deferred
>> > computation, I'd be really enthusiastic (subject to syntax and behavioral
>> > details).
>> >
>> > H
On Sat, Oct 23, 2021, 11:28 PM Chris Angelico wrote:
> > So stawman proposal:
> >
> > def fun(seq, low=0, high=defer: len(seq)):
> > assert low < high
> > # other stuff...
> >
> > Where the implication here is that the "defer expression" creates a
> dynamic scope.
>
> At what point
On 2021-10-24 at 13:23:51 +1100,
Steven D'Aprano wrote:
> On Sat, Oct 23, 2021 at 02:54:54PM -0700, 2qdxy4rzwzuui...@potatochowder.com
> wrote:
>
> [...]
> > > The function header is a syntactic construct - the "def" line, any
> > > decorators, annotations, etc.
> >
> > If you mean that def st
On Sat, Oct 23, 2021, 11:46 PM David Mertz, Ph.D.
> def f(x=defer: a + b):
>> a, b = 3, 5
>> return x
>>
>> Would this return 8, or a defer-expression? If 8, then the scope isn't
>> truly dynamic, since there's no way to keep it deferred until it moves to
>> another scope. If not 8, then I
On Sun, Oct 24, 2021 at 2:52 PM David Mertz, Ph.D.
wrote:
>
> On Sat, Oct 23, 2021, 11:46 PM David Mertz, Ph.D.
>>>
>>> def f(x=defer: a + b):
>>> a, b = 3, 5
>>> return x
>>>
>>> Would this return 8, or a defer-expression? If 8, then the scope isn't
>>> truly dynamic, since there's no wa
On Sat, Oct 23, 2021 at 9:21 PM Chris Angelico wrote:
> On Sun, Oct 24, 2021 at 2:52 PM David Mertz, Ph.D.
> wrote:
> >
> > On Sat, Oct 23, 2021, 11:46 PM David Mertz, Ph.D.
> >>>
> >>> def f(x=defer: a + b):
> >>> a, b = 3, 5
> >>> return x
> >>>
> >>> Would this return 8, or a defer-ex
Let's talk about the choice of spelling. So far, most of the suggested
syntaxes have modified the assignment symbol `=` using either a prefix
or a suffix. I'm going to use '?' as the generic modifier. So the
parameter will look like:
# Modifier as a prefix
param?=expression
param:Ty
On 2021-10-23 09:07, Chris Angelico wrote:
Proposal: Proper syntax and support for late-bound argument defaults.
def spaminate(thing, count=:thing.getdefault()):
...
I'm -1 on it.
For me the biggest problem with this idea is that it only handles a
subset of cases, namely
On Sun, Oct 24, 2021 at 3:43 PM Steven D'Aprano wrote:
> So far, I dislike all of those syntaxes (regardless of which symbol is
> used as the modifier). They are all predicated on the idea that this is
> a new sort of assignment, which I think is the wrong way to think about
> it. I think that the
On Sun, Oct 24, 2021 at 3:51 PM Brendan Barnwell wrote:
>
> On 2021-10-23 09:07, Chris Angelico wrote:
> > Proposal: Proper syntax and support for late-bound argument defaults.
> >
> > def spaminate(thing, count=:thing.getdefault()):
> > ...
>
> I'm -1 on it.
>
> For me the bi
On Sat, Oct 23, 2021 at 08:29:54PM -0700, Brendan Barnwell wrote:
> For me the biggest problem with this idea is that it only handles a
> subset of cases, namely those that can be expressed as an expression
> inlined into the function definition.
True. But that's equally true for default va
On Sun, Oct 24, 2021 at 02:09:59PM +1100, Chris Angelico wrote:
> The biggest problem with thunks is knowing when to trigger evaluation.
I think Algol solved that problem by having thunks a purely internal
mechanism, not a first-class value that users could store or pass
around.
> We already
52 matches
Mail list logo