Re: [Python-ideas] Delivery Status Notification (Failure)

2018-06-27 Thread Jacco van Dorp
Have you tried just instantiating a Counter() instead ? All missing keys are considerd to be 0 in a fresh counter. So for example: >>> c = Counter() >>> c["a"] += 1 >>> c Counter({'a': 1}) >>> c["b"] 0 works exactly this way. Which means there's no difference between what you're suggesting Counte

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Serhiy Storchaka
27.06.18 17:46, Ethan Furman пише: Question:   Should `SomeClass` be an enum member?  When would it be useful to have an embedded class in an Enum be an enum member? The only example I have seen so far of nested classes in an Enum is when folks want to make an Enum of Enums, and the nested

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread James Edwards
> >I'd want to see code that currently uses ``if isinstance`` to switch > between ``max(x)`` and ``x.max()``. I understand that, and I've spent a few hours searching github with less-than-stellar results due to github's search syntax ignoring '.' and '('

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Greg Ewing
Guido van Rossum wrote: Sounds to me really strange that the nested class would become a member. Probably because everything becomes a member unless it's a function (maybe decorated)? Maybe it would have been better if Enums got told what type their members are supposed to be, an only decorate

Re: [Python-ideas] Add a __cite__ method for scientific packages

2018-06-27 Thread Nathaniel Smith
On Wed, Jun 27, 2018 at 2:20 PM, Andrei Kucharavy wrote: > To remediate to that situation, I suggest a __citation__ method associated > to each package installation and import. Called from the __main__, > __citation__() would scan __citation__ of all imported packages and return > the list of all

Re: [Python-ideas] random.sample should work better with iterators

2018-06-27 Thread Abe Dillon
Let me start off by saying I agree with Tim Peters that it would be best to implement these changes in a new function (if ever). On Tuesday, June 26, 2018 at 8:06:35 PM UTC-5, Steven D'Aprano wrote: > > range is not an iterator. > My misunderstanding of the details of range objects was, indeed,

Re: [Python-ideas] Add a __cite__ method for scientific packages

2018-06-27 Thread Nathan Goldbaum
This is an interesting proposal. Speaking as a developer of scientific software packages it would be really cool to have support for something like this in the language itself. The software sustainability institute in the UK have written several blog posts advocating the use of CITATION files cont

Re: [Python-ideas] Add a __cite__ method for scientific packages

2018-06-27 Thread Guido van Rossum
While I'm not personally in need of citations (and never felt I was) I can easily understand the point -- sometimes citations can make or break a career and having written a popular software package should be acknowledged. Are there other languages or software communities that do something like th

[Python-ideas] Add a __cite__ method for scientific packages

2018-06-27 Thread Andrei Kucharavy
Over the last 10 years, Python has slowly inched towards becoming the most popular scientific computing language, beating or seriously challenging Matlab, R, Mathematica and many specialized languages (S, SAS, ...) in numerous applications. A large part of this growth is driven by amazing communit

[Python-ideas] collections.Counter should implement fromkeys

2018-06-27 Thread Abe Dillon
Consider the following update function for conway's game of life: from collections import Counter def update(live: Set[Tuple[Integer, Integer]]): counts = Counter.fromkeys(live, 0) + Counter(itertools.chain(neighbors(* cell) for cell in live)) flip = {cell for cell, count in counts.items(

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Elazar
Yes, Ryan. I mean a way to express something like sealed classes in scala/kotlin. The Enum class defines a finite region in which subclasses can be defined, thus allows verifying that "elif" cases are exhaustive, for exampe. It mostly helpful for static type checking, but it also helps readability

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Elazar
People working with sum types might expect the instances of the nested class to be instances of the enclosing class. So if the nested class is a namedtuple, you get a sum type. The only problem is that there's no way to express this subtype relationship in code. Elazar בתאריך יום ד׳, 27 ביוני 201

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Ryan Gonzalez
I *think* he's referring to something like this: class A(enum.Enum): class Inner(NamedTuple): ... isinstance(A.Inner(), A()) # True I *think* that's it. On June 27, 2018 2:26:23 PM Ethan Furman wrote: On 06/27/2018 12:04 PM, Elazar wrote: > בתאריך יום ד׳, 27 ביוני 2018, 11:59,

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Ethan Furman
On 06/27/2018 12:04 PM, Elazar wrote: > בתאריך יום ד׳, 27 ביוני 2018, 11:59, מאת Guido van Rossum: >> Sounds to me really strange that the nested class would become a member. >> Probably because everything becomes a member unless it's a function >> (maybe decorated)? > People working with sum ty

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Ethan Furman
On 06/27/2018 11:52 AM, Guido van Rossum wrote: Sounds to me really strange that the nested class would become a member. Probably because everything becomes a member unless it's a function (maybe decorated)? Pretty much. __dunders__, _sunders_, and descriptors do not get transformed. Every

Re: [Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Guido van Rossum
Sounds to me really strange that the nested class would become a member. Probably because everything becomes a member unless it's a function (maybe decorated)? On Wed, Jun 27, 2018 at 7:47 AM Ethan Furman wrote: > Consider the following Enum definition: > >class Color(Enum): >RED = 1

Re: [Python-ideas] Allow mutable builtin types (optionally)

2018-06-27 Thread Guido van Rossum
So the question remains -- why not use a heap type? On Wed, Jun 27, 2018 at 2:05 AM Greg wrote: > As I introduced (a long time ago) this demand, let me add my grain of salt > here. > > The use case is pretty simple, and somewhat common when writing manually C > extension class: The reason to wri

Re: [Python-ideas] random.sample should work better with iterators

2018-06-27 Thread Tim Peters
> > [Tim] > In Python today, the easiest way to spell Abe's intent is, e.g., > > > > >>> from heapq import nlargest # or nsmallest - doesn't matter > > >>> from random import random > > >>> nlargest(4, (i for i in range(10)), key=lambda x: random()) > > [75260, 45880, 99486, 13478] > > >>> nla

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Franklin? Lee
On Wed, Jun 27, 2018 at 11:30 AM, Michael Selik wrote: > On Wed, Jun 27, 2018 at 8:16 AM Franklin? Lee > wrote: >> >> On Wed, Jun 27, 2018, 10:31 Steven D'Aprano wrote: >>> >>> On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: >>> > My intent was to ask where a range was in fact pas

Re: [Python-ideas] random.sample should work better with iterators

2018-06-27 Thread Franklin? Lee
On Wed, Jun 27, 2018 at 3:11 AM, Antoine Pitrou wrote: > On Tue, 26 Jun 2018 23:52:55 -0500 > Tim Peters wrote: >> >> In Python today, the easiest way to spell Abe's intent is, e.g., >> >> >>> from heapq import nlargest # or nsmallest - doesn't matter >> >>> from random import random >> >>> nlarg

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Fiedler Roman
> Von: Michael Selik [mailto:m...@selik.org] > > On Wed, Jun 27, 2018 at 12:04 AM Fiedler Roman > wrote: > > Context: we are conducting machine learning experiments that > generate some kind of nested decision trees. As the tree includes specific > decision

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Fiedler Roman
> Von: Nick Coghlan [mailto:ncogh...@gmail.com] > > On 27 June 2018 at 17:04, Fiedler Roman wrote: > > Hello List, > > > > Context: we are conducting machine learning experiments that generate > some kind of nested decision trees. As the tree includes specific decision > elements (which require cu

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 8:16 AM Franklin? Lee wrote: > On Wed, Jun 27, 2018, 10:31 Steven D'Aprano wrote: > >> On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: >> > My intent was to ask where a range was in fact passed into max, not >> merely >> > where it could be. It'd be enlight

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Fiedler Roman
> Von: Guido van Rossum [mailto:gu...@python.org] > > I consider this is a bug -- a violation of Python's (informal) promise to the > user > that when CPython segfaults it is not the user's fault. Strictly it is not a segfault, just a parser exception that cannot be caught (at least I failed to

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Chris Barker - NOAA Federal via Python-ideas
I don’t think anyone would argue that there would be use cases for __max__ and __min__ special methods. However, there is substantial overhead to adding new magic methods, so the question is not whether it would be useful in some special cases, but whether it would be useful enough in common enou

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 12:04 AM Fiedler Roman wrote: > Context: we are conducting machine learning experiments that generate some > kind of nested decision trees. As the tree includes specific decision > elements (which require custom code to evaluate), we decided to store the > decision tree (r

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Nick Coghlan
On 27 June 2018 at 17:04, Fiedler Roman wrote: > Hello List, > > Context: we are conducting machine learning experiments that generate some > kind of nested decision trees. As the tree includes specific decision > elements (which require custom code to evaluate), we decided to store the > decis

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Franklin? Lee
On Wed, Jun 27, 2018, 10:31 Steven D'Aprano wrote: > On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: > > > > > Have you ever written ``max(range(x))`` in production code? > > > > > > I have never written that. > > > > > > But I have written ``max(iterable)`` dozens of times, where

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Antoine Pitrou
The OP says "crash" (implying some kind of segfault) but here the snippet raises a mere exception: Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> A([A([A([A([A([A([A([A([A([A([A([A([A([A([A

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018 at 7:30 AM Steven D'Aprano wrote: > On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: > > > > Have you ever written ``max(range(x))`` in production code? > > > I have never written that. > > > But I have written ``max(iterable)`` dozens of times, where iterable >

Re: [Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Guido van Rossum
I consider this is a bug -- a violation of Python's (informal) promise to the user that when CPython segfaults it is not the user's fault. Given typical Python usage patterns, I don't consider this an important bug, but maybe someone is interested in trying to fix it. As far as your application i

[Python-ideas] Should nested classes in an Enum be Enum members?

2018-06-27 Thread Ethan Furman
Consider the following Enum definition: class Color(Enum): RED = 1 GREEN = 2 BLUE = 3 @property def lower(self): return self.name.lower() def spam(self): return "I like %s eggs and spam!" % self.lower class SomeClass: pass

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Steven D'Aprano
On Wed, Jun 27, 2018 at 06:52:14AM -0700, Michael Selik wrote: > > > Have you ever written ``max(range(x))`` in production code? > > > > I have never written that. > > > > But I have written ``max(iterable)`` dozens of times, where iterable > > could be a range object. > > > > My intent was to as

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Wed, Jun 27, 2018, 3:06 AM Steven D'Aprano wrote: > On Wed, Jun 27, 2018 at 12:36:12AM -0700, Michael Selik wrote: > > On Tue, Jun 26, 2018, 11:43 PM Jacco van Dorp > wrote: > > > > Generators dont have a __len__ method. And they might have min/max > > > that can be calculated without iterati

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Steven D'Aprano
On Wed, Jun 27, 2018 at 12:36:12AM -0700, Michael Selik wrote: > On Tue, Jun 26, 2018, 11:43 PM Jacco van Dorp wrote: > > Generators dont have a __len__ method. And they might have min/max > > that can be calculated without iterating over the entire thing. The > > builtin range() is an example. (

Re: [Python-ideas] Have a "j" format option for lists

2018-06-27 Thread Antoine Pitrou
On Wed, 9 May 2018 09:39:08 -0300 Facundo Batista wrote: > This way, I could do: > > >>> authors = ["John", "Mary", "Estela"] > >>> "Authors: {:, j}".format(authors) > 'Authors: John, Mary, Estela' > > In this case the join can be made in the format yes, but this proposal > would be very usefu

Re: [Python-ideas] Allow mutable builtin types (optionally)

2018-06-27 Thread Eloi Gaudry
Hi Brett, Sorry about that, I did not mean to be rude. What I wanted to says is: 1. That I relied on such a feature 2. Other people on this mailing-list already asked something similar at several occasions 3. HEAPTYPE would not always be a solution 4. Then I thought this w

Re: [Python-ideas] Allow mutable builtin types (optionally)

2018-06-27 Thread Greg
As I introduced (a long time ago) this demand, let me add my grain of salt here. The use case is pretty simple, and somewhat common when writing manually C extension class: The reason to write extension class is usually performance, or link into an existing library. When doing this manually (inste

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Jacco van Dorp
2018-06-27 9:36 GMT+02:00 Michael Selik : > > > On Tue, Jun 26, 2018, 11:43 PM Jacco van Dorp wrote: >> >> 2018-06-26 17:34 GMT+02:00 Franklin? Lee : >> > Caller detects: The caller checks length before calling the dunder. If >> > there >> > is no dunder, it doesn't check. Are there real-world cas

Re: [Python-ideas] "Exposing" `__min__` and `__max__`

2018-06-27 Thread Michael Selik
On Tue, Jun 26, 2018, 11:43 PM Jacco van Dorp wrote: > 2018-06-26 17:34 GMT+02:00 Franklin? Lee : > > Caller detects: The caller checks length before calling the dunder. If > there > > is no dunder, it doesn't check. Are there real-world cases where length > is > > not defined on an iterable coll

Re: [Python-ideas] random.sample should work better with iterators

2018-06-27 Thread Antoine Pitrou
On Tue, 26 Jun 2018 23:52:55 -0500 Tim Peters wrote: > > In Python today, the easiest way to spell Abe's intent is, e.g., > > >>> from heapq import nlargest # or nsmallest - doesn't matter > >>> from random import random > >>> nlargest(4, (i for i in range(10)), key=lambda x: random()) > [

[Python-ideas] Correct way for writing Python code without causing interpreter crashes due to parser stack overflow

2018-06-27 Thread Fiedler Roman
Hello List, Context: we are conducting machine learning experiments that generate some kind of nested decision trees. As the tree includes specific decision elements (which require custom code to evaluate), we decided to store the decision tree (result of the analysis) as generated Python code.