From 1e668ca111563b122b16be5506638983b31205b5 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Thu, 9 Aug 2018 10:27:22 +0200 Subject: python: Better check for integer types Python 3 lost the long type: now everything is an int, with the right size. This commit makes the script compatible with Python 2 (where we check for both int and long) and Python 3 (where we only check for int). Signed-off-by: Mathieu Bridon Reviewed-by: Eric Engestrom Reviewed-by: Dylan Baker --- src/compiler/nir/nir_algebraic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/compiler/nir/nir_algebraic.py') diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 5baeea88afe..3055937029c 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -36,9 +36,11 @@ import traceback from nir_opcodes import opcodes if sys.version_info < (3, 0): + integer_types = (int, long) string_type = unicode else: + integer_types = (int, ) string_type = str _type_re = re.compile(r"(?Pint|uint|bool|float)?(?P\d+)?") @@ -81,7 +83,7 @@ class Value(object): return val elif isinstance(val, string_type): return Variable(val, name_base, varset) - elif isinstance(val, (bool, int, long, float)): + elif isinstance(val, (bool, float) + integer_types): return Constant(val, name_base) __template = mako.template.Template(""" @@ -145,7 +147,7 @@ class Constant(Value): def hex(self): if isinstance(self.value, (bool)): return 'NIR_TRUE' if self.value else 'NIR_FALSE' - if isinstance(self.value, (int, long)): + if isinstance(self.value, integer_types): return hex(self.value) elif isinstance(self.value, float): i = struct.unpack('Q', struct.pack('d', self.value))[0] @@ -164,7 +166,7 @@ class Constant(Value): def type(self): if isinstance(self.value, (bool)): return "nir_type_bool32" - elif isinstance(self.value, (int, long)): + elif isinstance(self.value, integer_types): return "nir_type_int" elif isinstance(self.value, float): return "nir_type_float" -- cgit v1.2.3