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

2021-08-22 Thread David Mertz, Ph.D.
Everyone in this thread should absolutely read Lewis Caroll's delightful and "What the Tortoise Said to Achilles." It's a very short 3-page story that addressed exactly this topic in 1895... even before Guido's Time Machine. One free copy of the public domain work is at:

[Python-ideas] Re: Notation for subscripts.

2021-08-22 Thread Matsuoka Takuo
Dear Developers, After some findings and further thoughts through this thread, I have formulated a proposal as follows. (I thank everyone who has commented in this thread). For the necessary definitions, please look at https://docs.python.org/3/reference/expressions.html#subscriptions

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

2021-08-22 Thread MRAB
On 2021-08-23 01:28, Steven D'Aprano wrote: On Sun, Aug 22, 2021 at 07:01:28PM +0300, Serhiy Storchaka wrote: (len(collection) == 0) is True Ha ha, yes, very good, you got me. But the trouble is, if you don't trust the truth value of the predicate, it is hard to know when to stop:

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

2021-08-22 Thread Steven D'Aprano
On Sun, Aug 22, 2021 at 07:01:28PM +0300, Serhiy Storchaka wrote: > (len(collection) == 0) is True Ha ha, yes, very good, you got me. But the trouble is, if you don't trust the truth value of the predicate, it is hard to know when to stop: len(collection) == 0 (len(collection) ==

[Python-ideas] Re: Add check_methods function to standard library

2021-08-22 Thread Finn Mason
Sorry, the formatting was terrible. I copy and pasted it from the original issue without really thinking about it. Here's the same thing, but actually readable: In _collections_abc.py is a private function titled _check_methods(). It takes a class and a number of method names (as strings), checks

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

2021-08-22 Thread Finn Mason
While this does comply with "explicit is better than implicit", there's another line of the Zen of Python that this idea definitely violates: "There should be one-- and preferably only one-- obvious way to do it." (Followed by the line "Although that way may not be obvious at first...", which I'd

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

2021-08-22 Thread Ricky Teachey
On Sun, Aug 22, 2021, 1:07 PM MRAB wrote: > On 2021-08-22 17:36, Thomas Grainger wrote: > > bool((len(collection) == 0) is True) == True and issubclass(True, bool) > > > 'True' is a reserved word, so you don't need to check it. > > However, 'bool' might have been overridden, so: > >

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

2021-08-22 Thread MRAB
On 2021-08-22 17:36, Thomas Grainger wrote: bool((len(collection) == 0) is True) == True and issubclass(True, bool) 'True' is a reserved word, so you don't need to check it. However, 'bool' might have been overridden, so: __builtins__.bool((len(collection) == 0) is True) == True Come to

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

2021-08-22 Thread Thomas Grainger
bool((len(collection) == 0) is True) == True and issubclass(True, bool) On Sun, 22 Aug 2021, 17:09 Valentin Berlier, wrote: > > (len(collection) == 0) is True > > bool((len(collection) == 0) is True) == True > ___ > Python-ideas mailing list --

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

2021-08-22 Thread Valentin Berlier
> (len(collection) == 0) is True bool((len(collection) == 0) is True) == True ___ 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-22 Thread Serhiy Storchaka
22.08.21 16:27, Steven D'Aprano пише: > Quoting the subject line: > > "We should have an explicit concept of emptiness for collections" > > We do. It's spelled: > > len(collection) == 0 > > You can't get more explicit than that. (len(collection) == 0) is True

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

2021-08-22 Thread Steven D'Aprano
Quoting the subject line: "We should have an explicit concept of emptiness for collections" We do. It's spelled: len(collection) == 0 You can't get more explicit than that. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To

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

2021-08-22 Thread Chris Angelico
On Sun, Aug 22, 2021 at 10:28 PM 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:

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

2021-08-22 Thread Tim Hoffmann via Python-ideas
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 len(seq): if not len(seq): In the talk "When Python Practices Go Wrong" Brandon

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

2021-08-22 Thread MRAB
On 2021-08-22 11:51, Matsuoka Takuo wrote: Dear developers, According to the Language Reference, a starred expression is defined by starred_expression ::= expression | (starred_item ",")* [starred_item] https://docs.python.org/3/reference/expressions.html#expression-lists However, in

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

2021-08-22 Thread Matsuoka Takuo
Dear developers, According to the Language Reference, a starred expression is defined by starred_expression ::= expression | (starred_item ",")* [starred_item] https://docs.python.org/3/reference/expressions.html#expression-lists However, in view of the definition of an assignment statement