Skip to content
Snippets Groups Projects
Commit e40200e0 authored by Mathieu Bridon's avatar Mathieu Bridon Committed by Eric Engestrom
Browse files

python: Don't abuse hex()


The hex() builtin returns a string containing the hexa-decimal
representation of an integer.

When the argument is not an integer, then the function calls that
object's __hex__() method, if one is defined. That method is supposed to
return a string.

While that's not explicitly documented, that string is supposed to be a
valid hexa-decimal representation for a number. Python 2 doesn't enforce
this though, which is why we got away with returning things like
'NIR_TRUE' which are not numbers.

In Python 3, the hex() builtin instead calls an object's __index__()
method, which itself must return an integer. That integer is then
automatically converted to a string with its hexa-decimal representation
by the rest of the hex() function.

As a result, we really can't make this compatible with Python 3 as it
is.

The solution is to stop using the hex() builtin, and instead use a hex()
object method, which can return whatever we want, in Python 2 and 3.

Signed-off-by: default avatarMathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: default avatarEric Engestrom <eric.engestrom@intel.com>
Reviewed-by: default avatarDylan Baker <dylan@pnwbakers.com>
parent 12eb5b49
No related branches found
Tags mesa-18.1.0-rc3
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment