[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 4, 2019, at 20:51, Inada Naoki wrote: >> And you’re right, because int|str _looks_ better than (int, str) here, many >> people will be encouraged to use it even though it’s slower, which could >> potentially be a bad thing for some programs. > > That's exactly my point. If we say "you

[Python-ideas] Re: Add a "block" option to Executor.submit

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 4, 2019, at 21:53, Anders Hovmöller wrote: > > >>> On 4 Sep 2019, at 22:58, Andrew Barnert wrote: >>> On Sep 4, 2019, at 10:17, Anders Hovmöller wrote: . >>> >>> Doesn't all that imply that it'd be good if you could just pass it the >>> queue object you want? >> >> P

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Chris Angelico
On Thu, Sep 5, 2019 at 7:08 PM Andrew Barnert via Python-ideas wrote: > > On Sep 4, 2019, at 20:51, Inada Naoki wrote: > > >> And you’re right, because int|str _looks_ better than (int, str) here, > >> many people will be encouraged to use it even though it’s slower, which > >> could potentiall

[Python-ideas] Conditional dict declarations

2019-09-05 Thread rls
Hi list I have a proposal for a minor (improvement?) to dict declarations. I find a common requirement I have is to include one or more entries in a dict only if some condition is met. Currently, the usual way of doing that is to add one or more if statements. Simple (but hopefully relatable-t

[Python-ideas] [OT] Designing for Concurrency (was: Add a "block" option to Executor.submit)

2019-09-05 Thread Dan Sommers
On 9/4/19 5:38 PM, Andrew Barnert via Python-ideas wrote: > On Sep 4, 2019, at 08:54, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: >> How does blocking the submit call differ from setting max_workers in >> the call to ThreadPoolExecutor? > Here’s a concrete example from my own code

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Steven D'Aprano
On Thu, Sep 05, 2019 at 07:15:27PM +1000, Chris Angelico wrote: > Hang on hang on what's this situation where you're checking types > of a zillion objects? An earlier version of the statistics module used lots of isinstance checks in order to support arbitrary numeric types, and was a lot s

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Paul Moore
On Thu, 5 Sep 2019 at 11:19, wrote: > I find a common requirement I have is to include one or more entries in a > dict only if some condition is met. Currently, the usual way of doing that is > to add one or more if statements. > > Simple (but hopefully relatable-to-real-world-code) example. [..

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Chris Angelico
On Thu, Sep 5, 2019 at 9:31 PM Steven D'Aprano wrote: > > On Thu, Sep 05, 2019 at 07:15:27PM +1000, Chris Angelico wrote: > > > Hang on hang on what's this situation where you're checking types > > of a zillion objects? > > An earlier version of the statistics module used lots of isinstance >

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Richard Musil
I was thinking more in this direction: d = dict() d[action in not None and 'action'] = action d[minval > 0 and 'minval'] = minval ... del d[False] There are few things I do not particularly like about this (assigning to dict, even when value is discarded later, or necessity of the del d[False]),

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread brian . skinn
I thought of something similar, but where the dict-literal construction is desired: >>> foo = True >>> bar = False >>> baz = False >>> d = { ... 'foo' if foo else None: 1, ... 'bar' if bar else None: 2, ... 'baz' if baz else None: 3, ... } >>> d {'foo': 1, None: 3} >>> d.pop(None) 3 >>> d {

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread brian . skinn
Okie, looks like my code got munched in the web view -- how do I make it not do that? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Sebastian Kreft
How is this different to the discussion https://mail.python.org/archives/list/python-ideas@python.org/thread/MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27/#MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27 ? On Thu, Sep 5, 2019 at 9:24 AM wrote: > Okie, looks like my code got munched in the web view -- how do I make > i

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 4, 2019, at 15:25, r...@hwyl.org wrote: > > ..."skip" being a unique object defined in and accessible from dict (there > may be better places to make it available). The dict insertion code then > simply ignores those entries when creating the dict. I’m a bit confused about exactly when t

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Brandt Bucher
Also worth noting is that dict.skip would live in dict.__dict__... which is a dict. Brandt > On Sep 5, 2019, at 08:51, Andrew Barnert via Python-ideas > wrote: > >> On Sep 4, 2019, at 15:25, r...@hwyl.org wrote: >> >> ..."skip" being a unique object defined in and accessible from dict (there

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Jan Verbeek
A problem with `(int, str)` that I believe hasn't been brought up yet is that it interferes with the existing use of subscription syntax, particularly by `Tuple`. `Tuple[int, str]` is equivalent to `Tuple[(int, str)]` but not to `Tuple[Union[int, str]]`, because `__getitem__` receives a single

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Andrew Barnert via Python-ideas
> On Sep 5, 2019, at 07:46, Sebastian Kreft wrote: > > How is this different to the discussion > https://mail.python.org/archives/list/python-ideas@python.org/thread/MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27/#MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27 > ? Well, that discussion started with an unworkable proposal

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 5, 2019, at 02:15, Chris Angelico wrote: > > On Thu, Sep 5, 2019 at 7:08 PM Andrew Barnert via Python-ideas > wrote: >> >> On Sep 4, 2019, at 20:51, Inada Naoki wrote: >> And you’re right, because int|str _looks_ better than (int, str) here, many people will be encouraged to

[Python-ideas] Re: [OT] Designing for Concurrency (was: Add a "block" option to Executor.submit)

2019-09-05 Thread Barry Scott
> On 5 Sep 2019, at 12:06, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> > wrote: > > Yes, you need some way to produce "back pressure" from downstream to > upstream, and to stop making new work (with new memory consumption) > until there's a place to put it. It seems that this is the impor

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Chris Angelico
On Fri, Sep 6, 2019 at 4:12 AM Andrew Barnert wrote: > > On Sep 5, 2019, at 02:15, Chris Angelico wrote: > > > > On Thu, Sep 5, 2019 at 7:08 PM Andrew Barnert via Python-ideas > > wrote: > >> > >> Which means if they run into a situation where they’re checking types of a > >> zillion objects, t

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 5, 2019, at 04:24, Steven D'Aprano wrote: > > But having said all that, I'm not sure that we should be rejecting this > proposal on the basis of performance when we haven't got any working > code to measure performance of :) Good point. But then if we never get any realistic use cases,

[Python-ideas] Re: [OT] Designing for Concurrency (was: Add a "block" option to Executor.submit)

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 5, 2019, at 11:13, Barry Scott wrote: > > > >> On 5 Sep 2019, at 12:06, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> >> wrote: >> >> Yes, you need some way to produce "back pressure" from downstream to >> upstream, and to stop making new work (with new memory consumption) >> until

[Python-ideas] Re: [OT] Designing for Concurrency (was: Add a "block" option to Executor.submit)

2019-09-05 Thread Andrew Barnert via Python-ideas
One thing I think is worth raising here: If my experience with concurrent.futures is far from universal, my expectations for this change may not be helpful, so let me lay that all out explicitly. In my experience, concurrent.futures has two very good, but very different, uses. First, there’s t

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Steven D'Aprano
On Thu, Sep 05, 2019 at 12:12:05PM -0700, Andrew Barnert wrote: > On Sep 5, 2019, at 04:24, Steven D'Aprano wrote: > > > > But having said all that, I'm not sure that we should be rejecting this > > proposal on the basis of performance when we haven't got any working > > code to measure perform

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Steven D'Aprano
On Tue, Sep 03, 2019 at 12:19:15PM -0700, Andrew Barnert via Python-ideas wrote: > On Sep 2, 2019, at 23:50, Philippe Prados wrote: > > > > Add a new operator for `Union[type1|type2]` ? > > Hold on. Are you proposing `Union[t1 | t2]` as a new spelling for > `Union[t1, t2]`? That seems pointless

[Python-ideas] Re: Inspired by Scala, a new syntax for Union type

2019-09-05 Thread Andrew Barnert via Python-ideas
Two more bits of bikeshedding… On Sep 5, 2019, at 12:12, Andrew Barnert via Python-ideas wrote: > >> On Sep 5, 2019, at 04:24, Steven D'Aprano wrote: >> >> If Union is a built-in, we could have something like this: >> >> def isinstance(obj, class_or_tuple): >> if type(class_or_tuple)

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Joao S. O. Bueno
Also, if one have in mind that dict addition with the `+` operator had been recelently approved, as of Python 3.9 it will be ok to write: ``` return ({ 'user_id': user_id,} + ({'max_results': max_results} if max_results else {}) + ({'active': active} if active is not None

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Guido van Rossum
On Thu, Sep 5, 2019 at 8:37 PM Joao S. O. Bueno wrote: > Also, if one have in mind that dict addition with the `+` operator had been > recelently approved > Where did you hear this? I am not aware that this was even made into a PEP let alone that such a PEP was approved. -- --Guido van Rossum