Are dicts supposed to raise comparison errors
Robin Becker
robin at reportlab.com
Wed Aug 1 09:25:25 EDT 2018
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):
return bytes.__hash__(self)
d={'a':1}
d[nbytes(b'a')] = d['a']
print(d)
d={nbytes(b'a'):1}
d['a'] = d[b'a']
print(d)
########################
> C:\code\hg-repos\reportlab\tmp>\python37\python -b tb1.py
> {'a': 1, b'a': 1}
> {b'a': 1, 'a': 1}
I expected one of the assignments to warn.
--
Robin Becker
More information about the Python-list
mailing list