[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Guido van Rossum
What sort of code would be able to do anything useful with either a sequence or a queue? Queues aren’t iterable. This seems a case of hyper-generalization. On Tue, Aug 24, 2021 at 22:19 Christopher Barker wrote: > Bringing this back on list: > > On Tue, Aug 24, 2021 at 9:58 PM David Mertz,

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Christopher Barker
On Tue, Aug 24, 2021 at 10:12 PM Guido van Rossum wrote: > “Container” is a kind of pun, it’s something with a __contains__ method. > The thing you’re looking for is “Collection”. > Hmm, perhaps we should tweak the docs, the section is titled: "Abstract Base Classes for Containers" But yes,

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Christopher Barker
Bringing this back on list: On Tue, Aug 24, 2021 at 9:58 PM David Mertz, Ph.D. wrote: > Sorry, I should have been more explicit. The several kinda of queues can > all "contain" items, but do not respond to len(). > yeah, I should have looked more closely at your list Though i would consider

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Guido van Rossum
“Container” is a kind of pun, it’s something with a __contains__ method. The thing you’re looking for is “Collection”, which is the base for sequences, mappings and sets. I also note that the discussion seems quite stuck. —Guido On Tue, Aug 24, 2021 at 21:55 Christopher Barker wrote: > It

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Christopher Barker
On Tue, Aug 24, 2021 at 9:50 PM Guido van Rossum wrote: > It was pointed out to me that numpy allows arrays that have no elements > but a nonzero first dimension. People could disagree about whether that > should be considered empty. > indeed -- you can kinda-sorta map an array to nested lists,

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Christopher Barker
It seems the conversation has confused two related concepts: 1) The default bool() implementation (Truthiness) -- this is what the OP said was recommended by PEP 8: "For sequences, (strings, lists, tuples), use the fact that empty sequences are false:" -- there is some debate about that whether

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Guido van Rossum
On Tue, Aug 24, 2021 at 7:23 PM MRAB wrote: > On 2021-08-25 00:48, Guido van Rossum wrote: > > Hi Tim, > > > > I'm sorry if this has been brought up before, but *aside from PEP 8* is > > there anything wrong with using "if len(a)" for nonempty, or "if not > > len(a)" for empty? > > > What is the

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread David Mertz, Ph.D.
I wanted to do a survey of various "aggregates" in Python to see if any stand out as making the usual `if stuff: ...` troublesome. I wrote a little script at https://github.com/DavidMertz/LanguagePractice/blob/main/python/aggregates.py . I'm being deliberately vague about an "aggregate." It

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread MRAB
On 2021-08-25 00:48, Guido van Rossum wrote: Hi Tim, I'm sorry if this has been brought up before, but *aside from PEP 8* is there anything wrong with using "if len(a)" for nonempty, or "if not len(a)" for empty? What is the cost of 'len'? If it's always O(1), then it's not a problem, but

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Ben Rudiak-Gould
On Tue, Aug 24, 2021 at 9:08 AM Jon Kiparsky wrote: > > Numbers in general are useful concepts that help us with real-world > > problems, but it's really hard to pin them down. > > Not that hard, really. A number is just a hackenbush game :) > RIP Berlekamp, Conway and Guy. They all died within

[Python-ideas] staticmethod with property

2021-08-24 Thread Henry Harutyunyan
Currently Python does not support using `@staticmethod` decorator along with `@property` decorator. I think that the it currently works is a bit misleading since it will not give an error, but gives the following outcome. ``` class Foo: @staticmethod @property def bar():

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Guido van Rossum
Hi Tim, I'm sorry if this has been brought up before, but *aside from PEP 8* is there anything wrong with using "if len(a)" for nonempty, or "if not len(a)" for empty? It would seem to work for numpy and pandas arrays, and it works for builtin sequences. Also, it has the advantage of being 100%

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Ethan Furman
On 8/24/21 4:35 PM, Cameron Simpson wrote: > If we're chasing rough edges, consider queue.Queue: > > >>> from queue import Queue > >>> Q = Queue() > >>> Q.empty() > True > >>> if Q: print("Q is true") > ... > Q is true > > I would often like to treat Queues as a

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Cameron Simpson
On 24Aug2021 06:55, tim.hoffm...@mailbox.org wrote: >Ethan Furman wrote: >> > "has element-wise operations" protocol or an is_empty protocol. >> > I consider emptiness-check a basic concept that should be consistent and >> > easy to use across containers. > >> Python has an emptiness-check and

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Tim Hoffmann via Python-ideas
Ethan Furman wrote: > On 8/24/21 3:03 PM, Tim Hoffmann via Python-ideas wrote: > > **How do you check if a container is empty?** > > IMHO the answer should not depend on the container. > I think this is the fly in the ointment -- just about everything, from len() > to bool(), to add, to iter()

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Ethan Furman
On 8/24/21 3:03 PM, Tim Hoffmann via Python-ideas wrote: > **How do you check if a container is empty?** > > IMHO the answer should not depend on the container. I think this is the fly in the ointment -- just about everything, from len() to bool(), to add, to iter() /all/ depend on the

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread David Mertz, Ph.D.
Oh, if I'm going to be a smart-ass, I should probably remember that I need a `not` in there. No need to correct me, I saw it as soon as pressing send. Nonetheless, this is an unnecessary method or function. Truthiness is non-emptiness for most purposes. And where it's not, you need something more

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Thomas Grainger
Right but this doesn't work with bumpy or pandas ___ 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-ideas.python.org/ Message archived at

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread David Mertz, Ph.D.
This is easy enough to put in your own toolkit: >>> is_empty = bool All done! On Tue, Aug 24, 2021, 6:04 PM Tim Hoffmann via Python-ideas < python-ideas@python.org> wrote: > I also have the feeling that this is going round in circles. So let me get > back to the core question: > > **How do you

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Tim Hoffmann via Python-ideas
I also have the feeling that this is going round in circles. So let me get back to the core question: **How do you check if a container is empty?** IMHO the answer should not depend on the container. While emptiness may mean different things for different types. The check syntax can and should

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Jon Kiparsky
> Numbers in general are useful concepts that help us with real-world > problems, but it's really hard to pin them down. Not that hard, really. A number is just a hackenbush game :) -jpk ___ Python-ideas mailing list -- python-ideas@python.org To

[Python-ideas] Notation for subscripts: refreshed proposal summary

2021-08-24 Thread Matsuoka Takuo
Dear Developers, Some of you may have noticed I updated my proposal on the subject yesterday. I'm afraid it was too long without a summary, so here is one. I hope this will be helpful to some people. Summary of the refreshed proposal - (1) Simplify the syntax:

[Python-ideas] Re: Definition of a starred expression in the Language Reference

2021-08-24 Thread Matsuoka Takuo
I have filed this at the issue tracker at https://bugs.python.org/issue44983 Best regards, Takuo ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Paul Moore
On Tue, 24 Aug 2021 at 12:07, Tim Hoffmann via Python-ideas wrote: > Just like length is. It's a basic concept and like __bool__ and __len__ it > should be upon the objects to specify what empty means. It feels like these arguments in the abstract are mostly going round in circles. It's

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Marc-Andre Lemburg
On 21.08.2021 23:33, Tim Hoffmann via Python-ideas wrote: > Hi all, > > The Programming Recommendations section in PEP-8 states > > "For sequences, (strings, lists, tuples), use the fact that empty sequences > are false:" > > # Correct: > if not seq: > if seq: > > # Wrong: > if

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Tim Hoffmann via Python-ideas
Christopher Barker wrote: > But I see no reason to add a standardized way to check for an empty > container- again “emptiness” may not be obviously defined either. > Numpy arrays, (or Pandas Dataframes) are a good example here — there are > more than one way to think of them as false - but maybe

[Python-ideas] Re: NAN handling in statistics functions

2021-08-24 Thread Marc-Andre Lemburg
On 24.08.2021 05:53, Steven D'Aprano wrote: > At the moment, the handling of NANs in the statistics module is > implementation dependent. In practice, that *usually* means that if your > data has a NAN in it, the result you get will probably be a NAN. > > >>> statistics.mean([1, 2,

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Chris Angelico
On Tue, Aug 24, 2021 at 4:31 PM Steven D'Aprano wrote: > ... midnight is not the annihilating element (zero). Unless you're Cinderella, of course. > We conventionally represent clock times as numbers, but they're more > akin to ordinal data. They have an order, but you can't do arithmetic on >

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Tim Hoffmann via Python-ideas
Ethan Furman wrote: > On 8/23/21 2:31 PM, Tim Hoffmann via Python-ideas wrote: > > Ethan Furman wrote: > > > It seems to me that the appropriate fix is for numpy to have an > > > "is_empty()" function > > that knows how to deal with arrays and array-like structures, not force > > every container

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Steven D'Aprano
On Mon, Aug 23, 2021 at 10:26:47PM -0700, Christopher Barker wrote: > On Mon, Aug 23, 2021 at 6:54 AM Thomas Grainger wrote: > > > here's another fun one "A False midnight": > > https://lwn.net/Articles/590299/ > > https://bugs.python.org/issue13936#msg212771 > > > This is a great example of

[Python-ideas] Re: We should have an explicit concept of emptiness for collections

2021-08-24 Thread Chris Angelico
On Tue, Aug 24, 2021 at 3:27 PM Christopher Barker wrote: > > On Mon, Aug 23, 2021 at 6:54 AM Thomas Grainger wrote: >> >> here's another fun one "A False midnight": https://lwn.net/Articles/590299/ >> https://bugs.python.org/issue13936#msg212771 > > > This is a great example of the problem of