Re: Are dicts supposed to raise comparison errors

2018-08-02 Thread Robin Becker
On 02/08/2018 08:20, Steven D'Aprano wrote: On Wed, 01 Aug 2018 22:14:54 +0300, Serhiy Storchaka wrote: ... Not always. If your code supported Python 2 in the past, or third-party dependencies supports or supported Python 2, this warning can expose a real bug. Even if all your and thir

Re: Are dicts supposed to raise comparison errors

2018-08-02 Thread Robin Becker
On 01/08/2018 18:19, Peter Otten wrote: I've looked into the actual code which has # paraparser.py f = isPy3 and asBytes or asUnicode K = list(known_entities.keys()) for k in K: known_entities[f(k)] = known_entities[k] It looks like known_entities starts out with the default stri

Re: Are dicts supposed to raise comparison errors

2018-08-02 Thread Steven D'Aprano
On Wed, 01 Aug 2018 22:14:54 +0300, Serhiy Storchaka wrote: > 01.08.18 21:03, Chris Angelico пише: >> And in any code that does not and cannot run on Python 2, the warning >> about bytes and text comparing unequal is nothing more than a false >> positive. > > Not always. If your code supported Py

Re: Are dicts supposed to raise comparison errors

2018-08-02 Thread Steven D'Aprano
On Wed, 01 Aug 2018 19:00:27 +0100, Paul Moore wrote: [...] > My point was that it's a *warning*, and as such it's perfectly possible > for a warning to *not* need addressing (other than to suppress or ignore > it once you're happy that doing so is the right approach). And my point was that ignor

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Serhiy Storchaka
01.08.18 21:03, Chris Angelico пише: And in any code that does not and cannot run on Python 2, the warning about bytes and text comparing unequal is nothing more than a false positive. Not always. If your code supported Python 2 in the past, or third-party dependencies supports or supported Py

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Thu, Aug 2, 2018 at 3:37 AM, Steven D'Aprano wrote: > In another post, Chris says: > > I suspect that there may be a bit of non-thinking-C-mentality > creeping in: "if I can turn on warnings, I should, and any > warning is a problem". That simply isn't the case in Python. > > I stro

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Paul Moore
On Wed, 1 Aug 2018 at 18:43, Steven D'Aprano wrote: > > On Wed, 01 Aug 2018 16:22:16 +0100, Paul Moore wrote: > > > If they've reported to you that your code produces warnings under -b, > > your response can quite reasonably be "thanks for the information, we've > > reviewed our bytes/string handl

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Steven D'Aprano
On Wed, 01 Aug 2018 16:22:16 +0100, Paul Moore wrote: > On Wed, 1 Aug 2018 at 16:10, Robin Becker wrote: >> >> On 01/08/2018 14:38, Chris Angelico wrote: >> > t's a warning designed to help people port code from Py2 to Py3. It's >> > not meant to catch every possible comparison. Unless you are ac

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Peter Otten
Paul Moore wrote: > On Wed, 1 Aug 2018 at 16:10, Robin Becker wrote: >> >> On 01/08/2018 14:38, Chris Angelico wrote: >> > t's a warning designed to help people port code from Py2 to Py3. It's >> > not meant to catch every possible comparison. Unless you are actually >> > porting Py2 code and are

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Thu, Aug 2, 2018 at 1:22 AM, Paul Moore wrote: > On Wed, 1 Aug 2018 at 16:10, Robin Becker wrote: >> >> On 01/08/2018 14:38, Chris Angelico wrote: >> > t's a warning designed to help people port code from Py2 to Py3. It's >> > not meant to catch every possible comparison. Unless you are actual

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Paul Moore
On Wed, 1 Aug 2018 at 16:10, Robin Becker wrote: > > On 01/08/2018 14:38, Chris Angelico wrote: > > t's a warning designed to help people port code from Py2 to Py3. It's > > not meant to catch every possible comparison. Unless you are actually > > porting Py2 code and are worried that you'll be ac

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Robin Becker
On 01/08/2018 14:38, Chris Angelico wrote: t's a warning designed to help people port code from Py2 to Py3. It's not meant to catch every possible comparison. Unless you are actually porting Py2 code and are worried that you'll be accidentally comparing bytes and text, just*don't use the -b switc

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 11:25 PM, Robin Becker wrote: > messing with bytes I discover that this doesn't warn with python -b > > > if __name__=='__main__': > class nbytes(bytes): > def __eq__(self,other): > return bytes.__eq__(self,other) if isinstanc

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Robin Becker
messing with bytes I discover that this doesn't warn with python -b if __name__=='__main__': class nbytes(bytes): def __eq__(self,other): return bytes.__eq__(self,other) if isinstance(other,bytes) else False def __hash__(self):

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 9:56 PM, Richard Damon wrote: >> it says explicitly that numeric keys will use numeric comparison, but >> no mention is made of strings/bytes etc etc and there's an implication >> that object identity is used rather than comparison. In python 3.x >> b'a' is not the same as '

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Richard Damon
On 8/1/18 4:36 AM, Robin Becker wrote: > On 31/07/2018 16:52, Chris Angelico wrote: >> On Wed, Aug 1, 2018 at 1:28 AM, MRAB wrote: >>> On 2018-07-31 08:40, Robin Becker wrote: A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings > . >>> The warning

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Robin Becker
.. Nope, that would be the effect of "and", not "or". "a" is b"b" and "fallback" False "a" is b"b" or "fallback" 'fallback' You seem to be caught in your wrong mental model. I recommend that you let the matter rest for a day or so, and then look at it with a fresh eye. .. my b

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 7:43 PM, Robin Becker wrote: > On 01/08/2018 09:52, Chris Angelico wrote: >> >> On Wed, Aug 1, 2018 at 6:36 PM, Robin Becker wrote: >>> >>> On 31/07/2018 16:52, Chris Angelico wrote: >> >> .. >>> >>> >>> it says explicitly that numeric keys will use numeric comparis

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Peter Otten
Robin Becker wrote: > On 01/08/2018 09:52, Chris Angelico wrote: >> On Wed, Aug 1, 2018 at 6:36 PM, Robin Becker wrote: >>> On 31/07/2018 16:52, Chris Angelico wrote: >>.. >>> >>> it says explicitly that numeric keys will use numeric comparison, but no > . >>> >> >> Technically,

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Robin Becker
On 01/08/2018 09:52, Chris Angelico wrote: On Wed, Aug 1, 2018 at 6:36 PM, Robin Becker wrote: On 31/07/2018 16:52, Chris Angelico wrote: .. it says explicitly that numeric keys will use numeric comparison, but no . Technically, the comparison used is: a is b or a == b

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Chris Angelico
On Wed, Aug 1, 2018 at 6:36 PM, Robin Becker wrote: > On 31/07/2018 16:52, Chris Angelico wrote: >> >> On Wed, Aug 1, 2018 at 1:28 AM, MRAB wrote: >>> >>> On 2018-07-31 08:40, Robin Becker wrote: A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings > > ..

Re: Are dicts supposed to raise comparison errors

2018-08-01 Thread Robin Becker
On 31/07/2018 16:52, Chris Angelico wrote: On Wed, Aug 1, 2018 at 1:28 AM, MRAB wrote: On 2018-07-31 08:40, Robin Becker wrote: A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings . The warning looks wrong to be. In Python 2, u'a' and b'a' would be treate

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Chris Angelico
On Wed, Aug 1, 2018 at 1:28 AM, MRAB wrote: > On 2018-07-31 08:40, Robin Becker wrote: >> >> A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings >> for some reportlab code; the >> example boils down to the following >> >> ## >> C:\code\hg-repos\reportlab\tmp>cat tb.p

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread MRAB
On 2018-07-31 08:40, Robin Becker wrote: A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings for some reportlab code; the example boils down to the following ## C:\code\hg-repos\reportlab\tmp>cat tb.py if __name__=='__main__': d={'a':1} d[b'a'] = d['a'

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Peter Otten
Robin Becker wrote: > On 31/07/2018 09:16, Paul Moore wrote: >> On 31 July 2018 at 08:40, Robin Becker wrote: >>> A bitbucket user complains that python 3.6.6 with -Wall -b prints >>> warnings for some reportlab code; the >>> example boils down to the following >>> >>> ## >>> C:\code\hg-r

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Paul Moore
On 31 July 2018 at 09:32, Robin Becker wrote: > On 31/07/2018 09:16, Paul Moore wrote: >> >> On 31 July 2018 at 08:40, Robin Becker wrote: >>> >>> A bitbucket user complains that python 3.6.6 with -Wall -b prints >>> warnings >>> for some reportlab code; the >>> example boils down to the followin

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Robin Becker
On 31/07/2018 09:16, Paul Moore wrote: On 31 July 2018 at 08:40, Robin Becker wrote: A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings for some reportlab code; the example boils down to the following ## C:\code\hg-repos\reportlab\tmp>cat tb.py if __name__=='__m

Re: Are dicts supposed to raise comparison errors

2018-07-31 Thread Paul Moore
On 31 July 2018 at 08:40, Robin Becker wrote: > A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings > for some reportlab code; the > example boils down to the following > > ## > C:\code\hg-repos\reportlab\tmp>cat tb.py > if __name__=='__main__': > d={'a':1} >

Are dicts supposed to raise comparison errors

2018-07-31 Thread Robin Becker
A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings for some reportlab code; the example boils down to the following ## C:\code\hg-repos\reportlab\tmp>cat tb.py if __name__=='__main__': d={'a':1} d[b'a'] = d['a'] ## C:\code\hg-repos\reportlab\tmp>