Re: [Python-ideas] Add a dict with the attribute access capability

2017-11-30 Thread Nick Coghlan
On 30 November 2017 at 05:11, Barry Warsaw wrote: > Serhiy Storchaka wrote: >> In 3.7 I have removed an old-deprecated plistlib.Dict. [1] Actually it >> already was deprecated when the plistlib module was added to the regular >> stdlib in Python 2.6. >> >> Raymond noticed that that capability seem

Re: [Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-11-30 Thread Nick Coghlan
On 1 December 2017 at 01:23, Ronald Oussoren wrote: > 1) Last time around Mark Shannon worried that this introduces infinite > recursion in the language itself (in my crummy summary, please read this > message to get the real concern >

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Greg Ewing
Steve Barnes wrote: Since the practical difference between remainder being the (partly exhausted) iterator and it being a list, (itself an iterator), A list is *not* an iterator, it's a sequence. There's a huge difference. Items of a sequence can be accessed at random, it can be iterated over

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ilya Kulakov
> Anyway, my expectation is that going along this way (i.e. removing all > runtime API apart from a necessary minimum) > will give a minor speed-up as compared to PEP 560 at the cost of a breaking > change (even for small number of developers). I don't think the change will be breaking: usage of

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Steve Barnes
On 30/11/2017 22:26, Greg Ewing wrote: > Steven D'Aprano wrote: >> On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: >> >>> Just a thought but what about a syntax something along the lines of: >>> >>> a, b, *remainder = iterable >>> >>> Where remainder becomes the iterable with the fi

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Greg Ewing
Steven D'Aprano wrote: On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: Just a thought but what about a syntax something along the lines of: a, b, *remainder = iterable Where remainder becomes the iterable with the first two values consumed by assigning to a & b. Guido's time

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ivan Levkivskyi
On 30 November 2017 at 22:38, Ilya Kulakov wrote: > A very rough implementation: > > typing.py: > > class _GenericMetaNoop(type): > def __getitem__(self, params): > return self > > class _GenericNoop(metaclass=_GenericMetaNoop) > pass > > GenericStub = Gene

Re: [Python-ideas] Add a dict with the attribute access capability

2017-11-30 Thread Greg Ewing
Ivan Pozdeev via Python-ideas wrote: I needed to hold an external function reference in an object instance (if I assigned it to an attribute, it was converted into an instance method). No, that only happens to functions stored in *class* attributes, not instance attributes. >>> class A: ...

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ilya Kulakov
A very rough implementation: typing.py: class _GenericMetaNoop(type): def __getitem__(self, params): return self class _GenericNoop(metaclass=_GenericMetaNoop) pass GenericStub = Generic if TYPE_CHECKING else _GenericNoop elsewhere.py: import typing

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ivan Levkivskyi
On 30 November 2017 at 22:25, Ilya Kulakov wrote: > My point is to have a class with public interface identical to > typing.Generic, but without all runtime overhead. > It's based on the assumption that few developers benefit with > typing.Generic addition during production application execution.

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ilya Kulakov
My point is to have a class with public interface identical to typing.Generic, but without all runtime overhead. It's based on the assumption that few developers benefit with typing.Generic addition during production application execution. Those who do, can subclass typing.Generic directly. > O

Re: [Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ivan Levkivskyi
On 30 November 2017 at 22:08, Ilya Kulakov wrote: > As explained in PEP 560, creation of Generic subclasses is much slower > (~7x on my machine). > My guess is that a limited number of applications actually need Generic > classes at "production" runtime (i.e. when not under analysis of mypy or >

[Python-ideas] Stub class for Generic to further improve PEP 560

2017-11-30 Thread Ilya Kulakov
As explained in PEP 560, creation of Generic subclasses is much slower (~7x on my machine). My guess is that a limited number of applications actually need Generic classes at "production" runtime (i.e. when not under analysis of mypy or IDE). I propose a special class that will alias typing.Gene

Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

2017-11-30 Thread Nick Timkovich
On Thu, Nov 30, 2017 at 12:24 PM, Brett Cannon wrote: > On Wed, 29 Nov 2017 at 13:28 Greg Ewing > wrote: > >> Nick Coghlan wrote: >> >> >>What about more English-like syntax: >> >> >> >>X or else Y >> > >> > The problem with constructs like this is that they look like they >> > should mean the s

Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

2017-11-30 Thread Chris Angelico
On Fri, Dec 1, 2017 at 5:45 AM, Tres Seaver wrote: >> I would *not* add any spelling for an explicit bare-except equivalent. >> You would have to write: >> >> val = name.strip()[4:].upper() except Exception as -1 > > > Wouldn't that really need to be this instead, for a true 'except:' > equival

Re: [Python-ideas] What's the status of PEP 505: None-aware operators?

2017-11-30 Thread Tres Seaver
On 11/29/2017 01:02 PM, Barry Warsaw wrote: > I don’t know whether I like any of this but I think a more > natural spelling would be: > > val = name.strip()[4:].upper() except (AttributeError, KeyError) as -1 > > which could devolve into: > > val = name.strip()[4:].upper() except KeyError

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Paul Moore
On 30 November 2017 at 16:16, Steve Barnes wrote: > I had a sneaky feeling that it did, which raises the question of what > the bleep this enormous thread is about, since the fundamental syntax > currently exists Essentially, it's about the fact that to build remainder you need to copy all of

[Python-ideas] PEP 505 vs matrix multiplication

2017-11-30 Thread Antoine Pitrou
On Wed, 29 Nov 2017 18:14:36 +1000 Nick Coghlan wrote: > > As far as utility goes, I put it in a similar category to matrix > multiplication: if you don't need it, you don't need it, but when you > do need it, you need it a *lot*. As someone who appreciates both the matrix multiplication operato

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Steve Barnes
On 30/11/2017 15:50, Steven D'Aprano wrote: > On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: > >> Just a thought but what about a syntax something along the lines of: >> >> a, b, *remainder = iterable >> >> Where remainder becomes the iterable with the first two values consumed >>

Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

2017-11-30 Thread Brett Cannon
On Wed, 29 Nov 2017 at 13:28 Greg Ewing wrote: > Nick Coghlan wrote: > > >>What about more English-like syntax: > >> > >>X or else Y > > > > The problem with constructs like this is that they look like they > > should mean the same thing as "X or Y". > > How about: > > x otherwise y > > It lo

[Python-ideas] Conditional exception catching, lexical exceptions, None-specific exceptions

2017-11-30 Thread Random832
On Wed, Nov 29, 2017, at 12:40, David Mertz wrote: > I like much of the thinking in Random's approach. But I still think > None isn't quite special enough to warrant it's own syntax. > > However, his '(or None: name.strip()[4:].upper())' makes me realize > that what is being asked in all the '?(',

Re: [Python-ideas] [Python-Dev] What's the status of PEP 505: None-aware operators?

2017-11-30 Thread Ivan Pozdeev via Python-ideas
On 29.11.2017 9:08, Steven D'Aprano wrote: On Tue, Nov 28, 2017 at 12:31:06PM -0800, Raymond Hettinger wrote: I also cc python-dev to see if anybody here is strongly in favor or against this inclusion. Put me down for a strong -1. The proposal would occasionally save a few keystokes but comes

[Python-ideas] PEP 447: Adding type.__getdescriptor__

2017-11-30 Thread Ronald Oussoren
Hi, I’m trying to get up to speed again w.r.t. PEP 447 (and to be honest, with CPython’s development workflow as its been too long since I’ve actually done work on the CPython codebase…). Let me start by recapping the PEP (

Re: [Python-ideas] Add a dict with the attribute access capability

2017-11-30 Thread Ivan Pozdeev via Python-ideas
I use argparse.Namespace whenever I need this. In reply to Chris Barker's concern of "is this code or is this data", the last time I used it is when I needed to hold an external function reference in an object instance (if I assigned it to an attribute, it was converted into an instance method

Re: [Python-ideas] How assignment should work with generators?

2017-11-30 Thread Steven D'Aprano
On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: > Just a thought but what about a syntax something along the lines of: > > a, b, *remainder = iterable > > Where remainder becomes the iterable with the first two values consumed > by assigning to a & b. Guido's time machine strike

Re: [Python-ideas] Immutable dictionaries

2017-11-30 Thread Stephan Houben
2017-11-30 2:16 GMT+01:00 Rob Cliffe : > This is sort of a subset of an idea I once posted on Python-Ideas: > Dictionaries, sets and lists (etc. ?) could have a mutable flag, and once > it was set to False you could neither change it back nor change the > object. (OK there might be some backdoor