New submission from Mark Dickinson <dicki...@gmail.com>:

The documentation[1] for comparisons between mixed types says:

> [...] when a binary arithmetic operator has operands of different
> numeric types, the operand with the "narrower" type is widened to
> that of the other, where integer is narrower than floating point,
> which is narrower than complex. Comparisons between numbers of
> mixed type use the same rule.

That "use the same rule" part of the last sentence is misleading: it suggests 
that (for example) when an int is compared with a float, the int is first 
converted to a float, and then the two floats are compared. But that's not what 
actually happens: instead, the exact values of the int and float are compared. 
(And it's essential that equality comparisons happen that way, else equality 
becomes intransitive and dictionaries with numeric keys get very confused as a 
result.)

I suggest dropping the last sentence and adding a new paragraph about 
comparisons between numbers of mixed type.




[1] 
https://github.com/python/cpython/blob/master/Doc/library/stdtypes.rst#numeric-types-----classint-classfloat-classcomplex

----------
assignee: docs@python
components: Documentation
messages: 361234
nosy: docs@python, mark.dickinson
priority: normal
severity: normal
status: open
title: Documentation about comparisons between numeric types is misleading
versions: Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39530>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to