[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Antoine Pitrou
On Tue, 28 Apr 2020 11:04:15 +1000 Steven D'Aprano wrote: > > Yes, it's annoying when English words can have two or more meanings. The > first time I can across math.sin, I was very excited, until I realised > it was just the trigonometric function :-( > > This is the gunslinger.draw versus th

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Oleg Broytman
On Tue, Apr 28, 2020 at 10:19:49AM +0200, Antoine Pitrou wrote: > On Tue, 28 Apr 2020 11:04:15 +1000 > Steven D'Aprano wrote: > > > > Yes, it's annoying when English words can have two or more meanings. The > > first time I can across math.sin, I was very excited, until I realised > > it was

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Edwin Zimmerman
On 4/27/2020 11:47 PM, Soni L. wrote: [snip] > tbh my particular case doesn't make a ton of practical sense. I have config > files and there may be errors opening or deserializing them, and I have a > system to manage configs and overrides. which means you can have multiple > config files, and y

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Barry Scott
> On 28 Apr 2020, at 02:04, Steven D'Aprano wrote: > > Yes, it's annoying when English words can have two or more meanings. The > first time I can across math.sin, I was very excited, until I realised > it was just the trigonometric function :-( @once def my_func(): ... I read that

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Steve Barnes
Actually the draw examples made me think that possibly the @once, @run_once or whatever decorator should possibly add a reset method, as does the lru_cache cache_clear function. Taking the gunslinger draw example it would be: @once def draw(): """ Get your gun """ # Get your gun ...

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-28 Thread Steven D'Aprano
On Mon, Apr 27, 2020 at 09:21:41AM -0700, Andrew Barnert wrote: > But this doesn’t do what the OP suggested; it’s a completely different > proposal. They wanted to write this: > > zipped = zip(xs, ys).skip() > > … and you’re offering this: > > zipped = zip.skip(xs, ys) > > That’s a de

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Soni L.
On 2020-04-28 7:50 a.m., Edwin Zimmerman wrote: On 4/27/2020 11:47 PM, Soni L. wrote: [snip] > tbh my particular case doesn't make a ton of practical sense. I have config files and there may be errors opening or deserializing them, and I have a system to manage configs and overrides. which m

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-28 Thread Brandt Bucher
Thanks for weighing in, everybody. Over the course of the last week, it has become surprisingly clear that this change is controversial enough to require a PEP. With that in mind, I've started drafting one summarizing the discussion that took place here, and arguing for the addition of a boolea

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-28 Thread Rhodri James
On 28/04/2020 15:46, Brandt Bucher wrote: Thanks for weighing in, everybody. Over the course of the last week, it has become surprisingly clear that this change is controversial enough to require a PEP. With that in mind, I've started drafting one summarizing the discussion that took place he

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Edwin Zimmerman
On April 28, 2020 9:38 AM Soni L. wrote: > On 2020-04-28 7:50 a.m., Edwin Zimmerman wrote: > > On 4/27/2020 11:47 PM, Soni L. wrote: > > [snip] > > > tbh my particular case doesn't make a ton of practical sense. I have > > > config files and there may be errors opening or deserializing > them, and

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Soni L.
On 2020-04-28 12:32 p.m., Edwin Zimmerman wrote: On April 28, 2020 9:38 AM Soni L. wrote: > On 2020-04-28 7:50 a.m., Edwin Zimmerman wrote: > > On 4/27/2020 11:47 PM, Soni L. wrote: > > [snip] > > > tbh my particular case doesn't make a ton of practical sense. I have config files and there may

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Chris Angelico
On Wed, Apr 29, 2020 at 1:50 AM Soni L. wrote: > > > > On 2020-04-28 12:32 p.m., Edwin Zimmerman wrote: > > On April 28, 2020 9:38 AM Soni L. wrote: > > > On 2020-04-28 7:50 a.m., Edwin Zimmerman wrote: > > > > On 4/27/2020 11:47 PM, Soni L. wrote: > > > > [snip] > > > > > tbh my particular case d

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Andrew Barnert via Python-ideas
On Apr 26, 2020, at 10:41, Guido van Rossum wrote: > >  > Since the function has no parameters and is pre-computed, why force all users > to *call* it? The @once decorator could just return the value of calling the > function: > > def once(func): > return func() > > @once > def pwd(): >

[Python-ideas] Re: extended for-else, extended continue, and a rant about zip()

2020-04-28 Thread Andrew Barnert via Python-ideas
On Apr 28, 2020, at 09:18, Chris Angelico wrote: > > I suggest forking CPython and implementing the feature. I’d suggest trying MacroPy first. There’s no way to get the desired syntax with macros, but at least at first glance it seems like you should be able to get the desired semantics with s

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Raymond Hettinger
> On Apr 26, 2020, at 7:03 AM, Tom Forbes wrote: > > I would like to suggest adding a simple “once” method to functools. As the > name suggests, this would be a decorator that would call the decorated > function, cache the result and return it with subsequent calls. It seems like you would ge

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Alex Hall
Some libraries implement a 'lazy object' which forwards all operations to a wrapped object, which gets lazily initialised once: https://github.com/ionelmc/python-lazy-object-proxy https://docs.djangoproject.com/en/3.0/_modules/django/utils/functional/ There's also a more general concept of proxyi

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Andrew Barnert via Python-ideas
On Apr 28, 2020, at 12:02, Alex Hall wrote: > > Some libraries implement a 'lazy object' which forwards all operations to a > wrapped object, which gets lazily initialised once: > > https://github.com/ionelmc/python-lazy-object-proxy > https://docs.djangoproject.com/en/3.0/_modules/django/utils

[Python-ideas] Re: Adding a "once" function to functools

2020-04-28 Thread Steven D'Aprano
On Tue, Apr 28, 2020 at 11:45:49AM -0700, Raymond Hettinger wrote: > It seems like you would get just about everything you want with one line: > > once = lru_cache(maxsize=None) But is it thread-safe? If you have a "once"ed expensive function with side-effects, and a second thread calls it