Are dicts supposed to raise comparison errors

Robin Becker robin at reportlab.com
Thu Aug 2 05:31:22 EDT 2018


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 string type, i. e.
> unicode in py3 and bytes in py2.
> 
> While in py2 the code has no effect in py3 it adds the corresponding keys of
> type bytes. However, known_entities is then used in
> HTMLParser.handle_entity_ref(self, name) which passes the name as unicode in
> py3.
>  > I didn't try, but I would suspect that the module keeps working as expected
> when you remove the lines quoted above.
>
I did try and all the tests pass in 2.7.x & >=3.3; the commit message says "fix entityref handling" and happened during the python 
3.x porting.
I suppose there was some issue, but its entirely probable that some later change (eg parser) has fixed the original problem and 
made this code redundant.

> If I'm correct running the program with the -b flag has at least helped in
> cleaning up the code in this case.
> 
and I will try running all tests under that flag; it's sure to find more issues.

> In other cases it might detect sources of bugs, so IMHO it's better to have
> a close look at and possibly rewrite code that triggers the warning rather
> than to disable it.
> -- 
Robin Becker




More information about the Python-list mailing list