Re: Expression can be simplified on list

2016-09-29 Thread Steve D'Aprano
On Fri, 30 Sep 2016 05:58 am, Random832 wrote: > On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: >> Your example is exactly what I am saying; if a type has a behavior in >> which all values are always True (true-ish) its a rather strange kind >> of bool-nature. > > For a given type T, if all

Re: Expression can be simplified on list

2016-09-29 Thread Chris Angelico
On Fri, Sep 30, 2016 at 5:58 AM, Random832 wrote: > On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: >> Your example is exactly what I am saying; if a type has a behavior in >> which all values are always True (true-ish) its a rather strange kind >> of bool-nature. > >

Re: Expression can be simplified on list

2016-09-29 Thread Random832
On Thu, Sep 29, 2016, at 02:47, Rustom Mody wrote: > Your example is exactly what I am saying; if a type has a behavior in > which all values are always True (true-ish) its a rather strange kind > of bool-nature. For a given type T, if all objects of type T are true (true-ish, truthy, whatever),

Re: Expression can be simplified on list

2016-09-29 Thread Terry Reedy
On 9/29/2016 2:47 AM, Rustom Mody wrote: On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: On 9/14/2016 3:16 AM, Rustom Mody wrote: In THOSE TYPES that element can justifiably serve as a falsey (empty) type However to extrapolate from here and believe that ALL TYPES

Re: Expression can be simplified on list

2016-09-29 Thread Terry Reedy
On 9/29/2016 12:36 PM, MRAB wrote: On 2016-09-29 16:56, Steve D'Aprano wrote: On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: What if an _exhausted_ iterator was falsey? Logic is about binary distinctions, rather than about 'truth'. For non-buggy iterator it, the useful binary distinction is

Re: Expression can be simplified on list

2016-09-29 Thread MRAB
On 2016-09-29 09:14, Steven D'Aprano wrote: On Thursday 29 September 2016 16:47, Rustom Mody wrote: On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: [...] Python make no such nonsense claim. By default, Python objects are truthy. >>> bool(object()) True Because

Re: Expression can be simplified on list

2016-09-29 Thread Chris Angelico
On Fri, Sep 30, 2016 at 2:36 AM, MRAB wrote: > On 2016-09-29 16:56, Steve D'Aprano wrote: >> >> On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: >> >>> What if an _exhausted_ iterator was falsey? >> >> >> >> The problem is that in general you can't tell if an iterator is

Re: Expression can be simplified on list

2016-09-29 Thread MRAB
On 2016-09-29 16:56, Steve D'Aprano wrote: On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: What if an _exhausted_ iterator was falsey? The problem is that in general you can't tell if an iterator is exhausted until you attempt to advance it. So even if bool(iterator) returns True, the call to

Re: Expression can be simplified on list

2016-09-29 Thread Steve D'Aprano
On Thu, 29 Sep 2016 09:53 pm, MRAB wrote: > What if an _exhausted_ iterator was falsey? The problem is that in general you can't tell if an iterator is exhausted until you attempt to advance it. So even if bool(iterator) returns True, the call to next() may raise StopIteration: def gen():

Re: Expression can be simplified on list

2016-09-29 Thread Peter Otten
MRAB wrote: > What if an _exhausted_ iterator was falsey? Many would expect it = iter("abc") while it: print(next(it)) to work (i. e. no StopIteration) -- if it doesn't, what's the actual usecase? If it does work there must be some lookahead which not all iterators can provide in a

Re: Expression can be simplified on list

2016-09-29 Thread MRAB
On 2016-09-29 10:49, Steven D'Aprano wrote: On Thursday 29 September 2016 18:45, Jussi Piitulainen wrote: [snip] What do you say about things like iterators and generators? I'd say they are containers, but they count as true even when they are empty. No, they aren't containers, because they

Re: Expression can be simplified on list

2016-09-29 Thread Steven D'Aprano
On Thursday 29 September 2016 18:45, Jussi Piitulainen wrote: > Steven D'Aprano writes: > > [- -] > >> What is this truthiness abstraction? It is the difference between >> "something" and "nothing". >> >> Values which represent nothing, e.g.: >> >> - None >> - numeric zero: 0, 0.0, 0j,

Re: Expression can be simplified on list

2016-09-29 Thread Lawrence D’Oliveiro
On Thursday, September 29, 2016 at 7:48:41 PM UTC+13, Rustom Mody wrote: > - And then uses a value of that type in a non-trivial bool-consuming position > such as the condition of an if/while etc > > There's a very good chance that bool-usage is buggy  --

Re: Expression can be simplified on list

2016-09-29 Thread Chris Angelico
On Thu, Sep 29, 2016 at 6:45 PM, Jussi Piitulainen wrote: > What do you say about things like iterators and generators? I'd say they > are containers, but they count as true even when they are empty. > > bool(x for x in [3,1] if x in [2,7]) # True > list(x for x in

Re: Expression can be simplified on list

2016-09-29 Thread Jussi Piitulainen
Steven D'Aprano writes: [- -] > What is this truthiness abstraction? It is the difference between > "something" and "nothing". > > Values which represent nothing, e.g.: > > - None > - numeric zero: 0, 0.0, 0j, Decimal(0) etc > - empty strings u'', '' > - empty containers [], (), {} etc. > > are

Re: Expression can be simplified on list

2016-09-29 Thread Steven D'Aprano
On Thursday 29 September 2016 16:47, Rustom Mody wrote: > On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: [...] >> Python make no such nonsense claim. By default, Python objects are truthy. >> >> >>> bool(object()) >> True >> >> Because True is the default, object

Re: Expression can be simplified on list

2016-09-29 Thread Chris Angelico
On Thu, Sep 29, 2016 at 4:47 PM, Rustom Mody wrote: >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. Classes with no falsey >> objects, such as functions, generators, and codes, need not do anything >>

Re: Expression can be simplified on list

2016-09-29 Thread Rustom Mody
On Thursday, September 15, 2016 at 1:43:05 AM UTC+5:30, Terry Reedy wrote: > On 9/14/2016 3:16 AM, Rustom Mody wrote: > > > In THOSE TYPES that element can justifiably serve as a falsey (empty) type > > > > However to extrapolate from here and believe that ALL TYPES can have a > > falsey > >

Re: Expression can be simplified on list

2016-09-17 Thread Piet van Oostrum
Daiyue Weng writes: > Hi, I found that when I tried to make an equality test on empty like, > > if errors == []: > > PyCharm always warns me, > > Expression can be simplified. > > I am wondering what's wrong and how to fix this? > It is not wrong, but it can be simplified

Re: Expression can be simplified on list

2016-09-14 Thread Jussi Piitulainen
Rustom Mody writes: > On Wednesday, September 14, 2016 at 5:35:53 PM UTC+5:30, Jussi Piitulainen > wrote: >> Mathematical discussions tend to acknowledge only alternation >> (union), concatenation and iteration (Kleene star) as operations, >> unless they specifically focus on some other

Re: Expression can be simplified on list

2016-09-14 Thread Steve D'Aprano
On Thu, 15 Sep 2016 08:46 am, Lawrence D’Oliveiro wrote: > On Thursday, September 15, 2016 at 9:12:25 AM UTC+12, Ned Batchelder > wrote: >> >> On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D’Oliveiro >> wrote: >>> >>> On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry

Re: Expression can be simplified on list

2016-09-14 Thread Lawrence D’Oliveiro
On Thursday, September 15, 2016 at 9:12:25 AM UTC+12, Ned Batchelder wrote: > > On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D’Oliveiro > wrote: >> >> On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: >>> >>> Because True is the default, object need not and

Re: Expression can be simplified on list

2016-09-14 Thread Ned Batchelder
On Wednesday, September 14, 2016 at 5:00:02 PM UTC-4, Lawrence D’Oliveiro wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: > > Because True is the default, object need not and at least in CPython > > does not have a __bool__ (or __len__) method. > > If they had

Re: Expression can be simplified on list

2016-09-14 Thread Chris Angelico
On Thu, Sep 15, 2016 at 6:59 AM, Lawrence D’Oliveiro wrote: > On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: >> Because True is the default, object need not and at least in CPython >> does not have a __bool__ (or __len__) method. > > If they had

Re: Expression can be simplified on list

2016-09-14 Thread Lawrence D’Oliveiro
On Thursday, September 15, 2016 at 8:13:05 AM UTC+12, Terry Reedy wrote: > Because True is the default, object need not and at least in CPython > does not have a __bool__ (or __len__) method. If they had to (in the absence of which a bool() cast would not work), then that would help prevent

Re: Expression can be simplified on list

2016-09-14 Thread Terry Reedy
On 9/14/2016 8:05 AM, Jussi Piitulainen wrote: Serhiy Storchaka writes: On 14.09.16 11:28, Steven D'Aprano wrote: I'm not sure if it makes sense to talk about an "empty regular expression", or if that is the same as re.compile(''). Presumably if such a thing makes sense, it would match

Re: Expression can be simplified on list

2016-09-14 Thread Terry Reedy
On 9/14/2016 3:16 AM, Rustom Mody wrote: In THOSE TYPES that element can justifiably serve as a falsey (empty) type However to extrapolate from here and believe that ALL TYPES can have a falsey value meaningfully, especially in some obvious fashion, is mathematically nonsense. Python make

Re: Expression can be simplified on list

2016-09-14 Thread Rustom Mody
On Wednesday, September 14, 2016 at 5:35:53 PM UTC+5:30, Jussi Piitulainen wrote: > Mathematical discussions tend to acknowledge only alternation (union), > concatenation and iteration (Kleene star) as operations, unless they > specifically focus on some other operations that can, in principle,

Re: Expression can be simplified on list

2016-09-14 Thread Jussi Piitulainen
Serhiy Storchaka writes: > On 14.09.16 11:28, Steven D'Aprano wrote: >> I'm not sure if it makes sense to talk about an "empty regular >> expression", or if that is the same as re.compile(''). Presumably if >> such a thing makes sense, it would match nothing, from any input at >> all. > >

Re: Expression can be simplified on list

2016-09-14 Thread Chris Angelico
On Wed, Sep 14, 2016 at 8:46 PM, Serhiy Storchaka wrote: > On 14.09.16 11:28, Steven D'Aprano wrote: >> >> I'm not sure if it makes sense to talk about an "empty regular >> expression", or >> if that is the same as re.compile(''). Presumably if such a thing makes >> sense, >>

Re: Expression can be simplified on list

2016-09-14 Thread Serhiy Storchaka
On 14.09.16 11:28, Steven D'Aprano wrote: I'm not sure if it makes sense to talk about an "empty regular expression", or if that is the same as re.compile(''). Presumably if such a thing makes sense, it would match nothing, from any input at all. Actually, it matches anything.

Re: Expression can be simplified on list

2016-09-14 Thread Steven D'Aprano
On Wednesday 14 September 2016 17:16, Rustom Mody wrote: > On Wednesday, September 14, 2016 at 10:23:12 AM UTC+5:30, Steven D'Aprano > wrote: >> And if somebody designed an iterator that behaved badly or surprisingly, >> would you conclude that the entire concept of iteration is therefore

Re: Expression can be simplified on list

2016-09-14 Thread Rustom Mody
On Wednesday, September 14, 2016 at 10:17:27 AM UTC+5:30, Steven D'Aprano wrote: > You're perfectly entitled to dislike duck-typed truthiness. But that makes > the > majority of dynamically-typed languages (like Python, Javascript, Ruby, Lua > and > more) a bad fit for your way of thinking.

Re: Expression can be simplified on list

2016-09-14 Thread Rustom Mody
On Wednesday, September 14, 2016 at 10:23:12 AM UTC+5:30, Steven D'Aprano wrote: > On Wednesday 14 September 2016 13:59, Lawrence D’Oliveiro wrote: > > > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > >> Lawrence D’Oliveiro writes: > >> > >> > It would be better if

Re: Expression can be simplified on list

2016-09-13 Thread Steven D'Aprano
On Wednesday 14 September 2016 13:59, Lawrence D’Oliveiro wrote: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: >> Lawrence D’Oliveiro writes: >> >> > It would be better if all such conversions were explicit >> >> Why? It's entirely unambiguous ... > >

Re: Expression can be simplified on list

2016-09-13 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: >> Lawrence D’Oliveiro writes: >> >> > It would be better if all such conversions were explicit >> >> Why? It's entirely unambiguous ... > > That's the story

Re: Expression can be simplified on list

2016-09-13 Thread Steven D'Aprano
On Wednesday 14 September 2016 12:16, Lawrence D’Oliveiro wrote: > On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: >> Why do you object to the type conversion to bool? > > It would be better if all such conversions were explicit, e.g. > > if bool(«non-bool expr»)

Re: Expression can be simplified on list

2016-09-13 Thread Ben Finney
Lawrence D’Oliveiro writes: > On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > > Lawrence D’Oliveiro writes: > > > > > It would be better if all such conversions were explicit > > > > Why? It's entirely unambiguous: the expression of an ‘if’

Re: Expression can be simplified on list

2016-09-13 Thread Lawrence D’Oliveiro
On Wednesday, September 14, 2016 at 2:25:48 PM UTC+12, Ben Finney wrote: > Lawrence D’Oliveiro writes: > > > It would be better if all such conversions were explicit > > Why? It's entirely unambiguous ... -- https://mail.python.org/mailman/listinfo/python-list

Re: Expression can be simplified on list

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 12:25 PM, Ben Finney wrote: > Lawrence D’Oliveiro writes: > >> On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: >> > Why do you object to the type conversion to bool? >> >> It would be better if

Re: Expression can be simplified on list

2016-09-13 Thread Ben Finney
Lawrence D’Oliveiro writes: > On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: > > Why do you object to the type conversion to bool? > > It would be better if all such conversions were explicit Why? It's entirely unambiguous: the expression of

Re: Expression can be simplified on list

2016-09-13 Thread Lawrence D’Oliveiro
On Tuesday, September 13, 2016 at 2:33:40 PM UTC+12, Ned Batchelder wrote: > Why do you object to the type conversion to bool? It would be better if all such conversions were explicit, e.g. if bool(«non-bool expr») : if not bool(«non-bool expr») : instead of if «non-bool expr» :

Re: Expression can be simplified on list

2016-09-13 Thread Chris Angelico
On Wed, Sep 14, 2016 at 9:16 AM, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > >> […] Thomas 'PointedEars' Lahn […] wrote: >>> If I knew that it is always going to be a list or a tuple, I would check >>> its length instead: >>> >>> if len(errors) == 0: >> >> I

Re: Expression can be simplified on list

2016-09-13 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote: > […] Thomas 'PointedEars' Lahn […] wrote: >> If I knew that it is always going to be a list or a tuple, I would check >> its length instead: >> >> if len(errors) == 0: > > I wouldn't. I'd use boolification here too. Only if I had to > distinguish between None, [], and

Re: Expression can be simplified on list

2016-09-12 Thread Ned Batchelder
On Monday, September 12, 2016 at 5:21:51 PM UTC-4, Thomas 'PointedEars' Lahn wrote: > Chris Angelico wrote: > > > On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: > > If you know that 'errors' is always going to be a list, you can check > > for emptiness thus: > > > >

Re: Expression can be simplified on list

2016-09-12 Thread Chris Angelico
On Tue, Sep 13, 2016 at 7:21 AM, Thomas 'PointedEars' Lahn wrote: > If I knew that it is always going to be a list or a tuple, I would check its > length instead: > > if len(errors) == 0: I wouldn't. I'd use boolification here too. Only if I had to distinguish between None,

Re: Expression can be simplified on list

2016-09-12 Thread Thomas 'PointedEars' Lahn
Chris Angelico wrote: > On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: >> Hi, I found that when I tried to make an equality test on empty like, >> >> if errors == []: >> >> PyCharm always warns me, >> >> Expression can be simplified. >> >> I am wondering what's wrong

Re: Expression can be simplified on list

2016-09-12 Thread Chris Angelico
On Mon, Sep 12, 2016 at 9:14 PM, Daiyue Weng wrote: > Hi, I found that when I tried to make an equality test on empty like, > > if errors == []: > > PyCharm always warns me, > > Expression can be simplified. > > I am wondering what's wrong and how to fix this? > If you know