From 562aa3a409f79d1b40becf227911c4572b20cba3 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 12 Mar 2019 17:51:12 +0200 Subject: [PATCH] Drop support for legacy Python 2.7 --- .travis.yml | 1 - example/arith_lib/test_Dec.py | 2 +- example/arith_lib/test_LeadZeroDet.py | 2 +- myhdl/_Cosimulation.py | 10 ++-- myhdl/_ShadowSignal.py | 5 +- myhdl/_Signal.py | 13 +++-- myhdl/_bin.py | 5 +- myhdl/_block.py | 8 ++- myhdl/_compat.py | 70 --------------------------- myhdl/_concat.py | 10 ++-- myhdl/_delay.py | 4 +- myhdl/_enum.py | 3 +- myhdl/_intbv.py | 32 ++++++------ myhdl/_modbv.py | 3 +- myhdl/_util.py | 5 +- myhdl/conversion/_analyze.py | 15 ++---- myhdl/conversion/_misc.py | 6 +-- myhdl/conversion/_toVHDL.py | 14 +++--- myhdl/conversion/_toVerilog.py | 17 +++---- myhdl/test/conftest.py | 5 +- myhdl/test/core/test_Cosimulation.py | 25 +++++----- myhdl/test/core/test_ShadowSignal.py | 5 +- myhdl/test/core/test_Signal.py | 27 +++++------ myhdl/test/core/test_bin.py | 3 +- myhdl/test/core/test_concat.py | 19 ++++---- myhdl/test/core/test_intbv.py | 69 +++++++++++++------------- myhdl/test/core/test_modbv.py | 1 - setup.py | 11 +++-- tox.ini | 2 +- 29 files changed, 142 insertions(+), 250 deletions(-) delete mode 100644 myhdl/_compat.py diff --git a/.travis.yml b/.travis.yml index 337774bd..4555d2c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ language: python python: - "3.7" - "3.6" - - "2.7" - "pypy3.5" install: diff --git a/example/arith_lib/test_Dec.py b/example/arith_lib/test_Dec.py index 63e36d74..dee68b4d 100644 --- a/example/arith_lib/test_Dec.py +++ b/example/arith_lib/test_Dec.py @@ -37,7 +37,7 @@ class DecTest(TestCase): @instance def stimulus(): if nrsamples: - vals = [long(random()*(2**width)) for i in range(nrsamples)] + vals = [int(random()*(2**width)) for i in range(nrsamples)] else: vals = range(2**width) for i in vals: diff --git a/example/arith_lib/test_LeadZeroDet.py b/example/arith_lib/test_LeadZeroDet.py index ff48f427..f392805d 100644 --- a/example/arith_lib/test_LeadZeroDet.py +++ b/example/arith_lib/test_LeadZeroDet.py @@ -37,7 +37,7 @@ class LeadZeroDetTest(TestCase): @instance def stimulus(): if nrsamples: - vals = [long(random()*(2**width)) for i in range(nrsamples)] + vals = [int(random()*(2**width)) for i in range(nrsamples)] else: vals = range(2**width) for i in vals: diff --git a/myhdl/_Cosimulation.py b/myhdl/_Cosimulation.py index dcceb2e1..f19a27b3 100644 --- a/myhdl/_Cosimulation.py +++ b/myhdl/_Cosimulation.py @@ -24,10 +24,10 @@ import sys import os #import shlex import subprocess +from os import set_inheritable from myhdl._intbv import intbv from myhdl import _simulator, CosimulationError -from myhdl._compat import set_inheritable, string_types, to_bytes, to_str _MAXLINE = 4096 @@ -84,7 +84,7 @@ class Cosimulation(object): env['MYHDL_TO_PIPE'] = str(msvcrt.get_osfhandle(wt)) env['MYHDL_FROM_PIPE'] = str(msvcrt.get_osfhandle(rf)) - if isinstance(exe, string_types): + if isinstance(exe, str): # exe = shlex.split(exe) exe = exe.split(' ') @@ -99,7 +99,7 @@ class Cosimulation(object): os.close(wt) os.close(rf) while 1: - s = to_str(os.read(rt, _MAXLINE)) + s = os.read(rt, _MAXLINE).decode() if not s: raise CosimulationError(_error.SimulationEnd) e = s.split() @@ -141,7 +141,7 @@ class Cosimulation(object): def _get(self): if not self._getMode: return - buf = to_str(os.read(self._rt, _MAXLINE)) + buf = os.read(self._rt, _MAXLINE).decode() if not buf: raise CosimulationError(_error.SimulationEnd) e = buf.split() @@ -180,7 +180,7 @@ class Cosimulation(object): if buf[-1] == 'L': buf = buf[:-1] # strip trailing L buflist.append(buf) - os.write(self._wf, to_bytes(" ".join(buflist))) + os.write(self._wf, (" ".join(buflist)).encode()) self._getMode = 1 def _waiter(self): diff --git a/myhdl/_ShadowSignal.py b/myhdl/_ShadowSignal.py index e9bbd8e4..54333737 100644 --- a/myhdl/_ShadowSignal.py +++ b/myhdl/_ShadowSignal.py @@ -26,7 +26,6 @@ from __future__ import absolute_import import warnings from copy import deepcopy -from myhdl._compat import long from myhdl._Signal import _Signal from myhdl._Waiter import _SignalWaiter, _SignalTupleWaiter from myhdl._intbv import intbv @@ -143,12 +142,12 @@ class ConcatSignal(_ShadowSignal): v = a elif isinstance(a, str): w = len(a) - v = long(a, 2) + v = int(a, 2) else: raise TypeError("ConcatSignal: inappropriate argument type: %s" % type(a)) nrbits += w - val = val << w | v & (long(1) << w) - 1 + val = val << w | v & (1 << w) - 1 self._initval = val ini = intbv(val)[nrbits:] _ShadowSignal.__init__(self, ini) diff --git a/myhdl/_Signal.py b/myhdl/_Signal.py index 32abb7cb..07c9844b 100644 --- a/myhdl/_Signal.py +++ b/myhdl/_Signal.py @@ -31,7 +31,6 @@ from __future__ import print_function from copy import copy, deepcopy -from myhdl._compat import integer_types, long from myhdl import _simulator as sim from myhdl._simulator import _futureEvents from myhdl._simulator import _siglist @@ -148,8 +147,8 @@ class _Signal(object): self._setNextVal = self._setNextBool self._printVcd = self._printVcdBit self._nrbits = 1 - elif isinstance(val, integer_types): - self._type = integer_types + elif isinstance(val, int): + self._type = (int,) self._setNextVal = self._setNextInt elif isinstance(val, intbv): self._type = intbv @@ -205,7 +204,7 @@ class _Signal(object): self._val = None elif isinstance(val, intbv): self._val._val = next._val - elif isinstance(val, (integer_types, EnumItemType)): + elif isinstance(val, (int, EnumItemType)): self._val = next else: self._val = deepcopy(next) @@ -294,14 +293,14 @@ class _Signal(object): def _setNextInt(self, val): if isinstance(val, intbv): val = val._val - elif not isinstance(val, (integer_types, intbv)): + elif not isinstance(val, (int, intbv)): raise TypeError("Expected int or intbv, got %s" % type(val)) self._next = val def _setNextIntbv(self, val): if isinstance(val, intbv): val = val._val - elif not isinstance(val, integer_types): + elif not isinstance(val, int): raise TypeError("Expected int or intbv, got %s" % type(val)) self._next._val = val self._next._handleBounds() @@ -494,7 +493,7 @@ class _Signal(object): return int(self._val) def __long__(self): - return long(self._val) + return int(self._val) def __float__(self): return float(self._val) diff --git a/myhdl/_bin.py b/myhdl/_bin.py index 1d5273bf..20299a7e 100644 --- a/myhdl/_bin.py +++ b/myhdl/_bin.py @@ -20,9 +20,6 @@ """ module with the bin function. """ -from myhdl._compat import long - - def _int2bitstring(num): if num == 0: return '0' @@ -46,7 +43,7 @@ def bin(num, width=0): Optional parameter: width -- specifies the desired string (sign bit padding) """ - num = long(num) + num = int(num) s = _int2bitstring(num) if width: pad = '0' diff --git a/myhdl/_block.py b/myhdl/_block.py index 77396ec8..0bae3b30 100644 --- a/myhdl/_block.py +++ b/myhdl/_block.py @@ -26,7 +26,6 @@ import inspect import functools import myhdl -from myhdl._compat import PY2 from myhdl import BlockError, BlockInstanceError, Cosimulation from myhdl._instance import _Instantiator from myhdl._util import _flatten @@ -74,10 +73,9 @@ def _getCallInfo(): callerrec = stack[4] # special case for list comprehension's extra scope in PY3 if name == '': - if not PY2: - funcrec = stack[4] - if len(stack) > 5: - callerrec = stack[5] + funcrec = stack[4] + if len(stack) > 5: + callerrec = stack[5] name = funcrec[3] frame = funcrec[0] diff --git a/myhdl/_compat.py b/myhdl/_compat.py deleted file mode 100644 index c4683fd9..00000000 --- a/myhdl/_compat.py +++ /dev/null @@ -1,70 +0,0 @@ -''' - - -''' - -import sys -import types - -PY2 = sys.version_info[0] == 2 -PYPY = hasattr(sys, 'pypy_translation_info') - -_identity = lambda x: x - -if not PY2: - string_types = (str,) - integer_types = (int,) - long = int - class_types = (type,) - - from io import StringIO - from os import set_inheritable - import builtins - - def to_bytes(s): - return s.encode() - - def to_str(b): - return b.decode() - -else: - string_types = (str, unicode) - integer_types = (int, long) - long = long - class_types = (type, types.ClassType) - - from cStringIO import StringIO - import __builtin__ as builtins - - to_bytes = _identity - to_str = _identity - - def set_inheritable(fd, inheritable): - # This implementation of set_inheritable is based on a code sample in - # [PEP 0446](https://www.python.org/dev/peps/pep-0446/) and on the - # CPython implementation of that proposal which can be browsed [here] - # (hg.python.org/releasing/3.4/file/8671f89107c8/Modules/posixmodule.c#l11130) - if sys.platform == "win32": - import msvcrt -# import ctypes.windll.kernel32 as kernel32 - import ctypes - windll = ctypes.LibraryLoader(ctypes.WinDLL) - SetHandleInformation = windll.kernel32.SetHandleInformation - - HANDLE_FLAG_INHERIT = 1 - - if SetHandleInformation(msvcrt.get_osfhandle(fd), - HANDLE_FLAG_INHERIT, - 1 if inheritable else 0) == 0: - raise IOError("Failed on HANDLE_FLAG_INHERIT") - else: - import fcntl - - fd_flags = fcntl.fcntl(fd, fcntl.F_GETFD) - - if inheritable: - fd_flags &= ~fcntl.FD_CLOEXEC - else: - fd_flags |= fcntl.FD_CLOEXEC - - fcntl.fcntl(fd, fcntl.F_SETFD, fd_flags) diff --git a/myhdl/_concat.py b/myhdl/_concat.py index dda5accd..a9b7944e 100644 --- a/myhdl/_concat.py +++ b/myhdl/_concat.py @@ -24,10 +24,8 @@ """ from __future__ import absolute_import -from myhdl._compat import integer_types from myhdl._intbv import intbv from myhdl._Signal import _Signal -from myhdl._compat import long def concat(base, *args): @@ -35,7 +33,7 @@ def concat(base, *args): if isinstance(base, intbv): basewidth = base._nrbits val = base._val - elif isinstance(base, integer_types): + elif isinstance(base, int): if isinstance(base, bool): basewidth = 1 else: @@ -49,7 +47,7 @@ def concat(base, *args): val = base._val elif isinstance(base, str): basewidth = len(base) - val = long(base, 2) + val = int(base, 2) else: raise TypeError("concat: inappropriate first argument type: %s" % type(base)) @@ -70,14 +68,14 @@ def concat(base, *args): v = arg elif isinstance(arg, str): w = len(arg) - v = long(arg, 2) + v = int(arg, 2) else: raise TypeError("concat: inappropriate argument type: %s" % type(arg)) if not w: raise TypeError("concat: arg on pos %d should have length" % (i + 1)) width += w - val = val << w | v & (long(1) << w) - 1 + val = val << w | v & (1 << w) - 1 if basewidth: return intbv(val, _nrbits=basewidth + width) diff --git a/myhdl/_delay.py b/myhdl/_delay.py index a252f92a..4c0a5eb0 100644 --- a/myhdl/_delay.py +++ b/myhdl/_delay.py @@ -20,8 +20,6 @@ """ Module that provides the delay class.""" from __future__ import absolute_import -from myhdl._compat import integer_types - _errmsg = "arg of delay constructor should be a natural integeer" @@ -36,6 +34,6 @@ class delay(object): val -- a natural integer representing the desired delay """ - if not isinstance(val, integer_types) or val < 0: + if not isinstance(val, int) or val < 0: raise TypeError(_errmsg) self._time = val diff --git a/myhdl/_enum.py b/myhdl/_enum.py index fafcf2e6..a33ef1bc 100644 --- a/myhdl/_enum.py +++ b/myhdl/_enum.py @@ -24,7 +24,6 @@ from __future__ import absolute_import from myhdl._bin import bin from myhdl._Signal import _Signal -from myhdl._compat import string_types # from myhdl.conversion._VHDLNameValidation import _nameValid @@ -58,7 +57,7 @@ def enum(*names, **kwargs): codedict = {} i = 0 for name in names: - if not isinstance(name, string_types): + if not isinstance(name, str): raise TypeError() if name in codedict: raise ValueError("enum literals should be unique") diff --git a/myhdl/_intbv.py b/myhdl/_intbv.py index 887bc9fc..bdfc3ee5 100644 --- a/myhdl/_intbv.py +++ b/myhdl/_intbv.py @@ -20,8 +20,8 @@ """ Module with the intbv class """ from __future__ import absolute_import, division +import builtins -from myhdl._compat import long, integer_types, string_types, builtins from myhdl._bin import bin @@ -43,11 +43,11 @@ class intbv(object): else: # make sure there is a leading zero bit in positive numbers _nrbits = builtins.max(len(bin(max - 1)) + 1, len(bin(min))) - if isinstance(val, integer_types): + if isinstance(val, int): self._val = val - elif isinstance(val, string_types): + elif isinstance(val, str): mval = val.replace('_', '') - self._val = long(mval, 2) + self._val = int(mval, 2) _nrbits = len(mval) elif isinstance(val, intbv): self._val = val._val @@ -138,7 +138,7 @@ class intbv(object): if i <= j: raise ValueError("intbv[i:j] requires i > j\n" " i, j == %s, %s" % (i, j)) - res = intbv((self._val & (long(1) << i) - 1) >> j, _nrbits=i - j) + res = intbv((self._val & (1 << i) - 1) >> j, _nrbits=i - j) return res else: i = int(key) @@ -157,15 +157,15 @@ class intbv(object): raise ValueError("intbv[i:j] = v requires j >= 0\n" " j == %s" % j) if i is None: # default - q = self._val % (long(1) << j) - self._val = val * (long(1) << j) + q + q = self._val % (1 << j) + self._val = val * (1 << j) + q self._handleBounds() return i = int(i) if i <= j: raise ValueError("intbv[i:j] = v requires i > j\n" " i, j, v == %s, %s, %s" % (i, j, val)) - lim = (long(1) << (i - j)) + lim = (1 << (i - j)) if val >= lim or val < -lim: raise ValueError("intbv[i:j] = v abs(v) too large\n" " i, j, v == %s, %s, %s" % (i, j, val)) @@ -176,9 +176,9 @@ class intbv(object): else: i = int(key) if val == 1: - self._val |= (long(1) << i) + self._val |= (1 << i) elif val == 0: - self._val &= ~(long(1) << i) + self._val &= ~(1 << i) else: raise ValueError("intbv[i] = v requires v in (0, 1)\n" " i == %s " % i) @@ -254,9 +254,9 @@ class intbv(object): def __lshift__(self, other): if isinstance(other, intbv): - return intbv(long(self._val) << other._val) + return intbv(int(self._val) << other._val) else: - return intbv(long(self._val) << other) + return intbv(int(self._val) << other) def __rlshift__(self, other): return other << self._val @@ -350,7 +350,7 @@ class intbv(object): self._val **= other._val else: self._val **= other - if not isinstance(self._val, integer_types): + if not isinstance(self._val, int): raise ValueError("intbv value should be integer") self._handleBounds() return self @@ -380,7 +380,7 @@ class intbv(object): return self def __ilshift__(self, other): - self._val = long(self._val) + self._val = int(self._val) if isinstance(other, intbv): self._val <<= other._val else: @@ -407,7 +407,7 @@ class intbv(object): def __invert__(self): if self._nrbits and self._min >= 0: - return intbv(~self._val & (long(1) << self._nrbits) - 1) + return intbv(~self._val & (1 << self._nrbits) - 1) else: return intbv(~self._val) @@ -415,7 +415,7 @@ class intbv(object): return int(self._val) def __long__(self): - return long(self._val) + return int(self._val) def __float__(self): return float(self._val) diff --git a/myhdl/_modbv.py b/myhdl/_modbv.py index 8a85768c..b14ea6e2 100644 --- a/myhdl/_modbv.py +++ b/myhdl/_modbv.py @@ -21,7 +21,6 @@ from __future__ import absolute_import from ._intbv import intbv -from ._compat import long class modbv(intbv): @@ -54,7 +53,7 @@ class modbv(intbv): if i <= j: raise ValueError("modbv[i:j] requires i > j\n" " i, j == %s, %s" % (i, j)) - res = modbv((self._val & (long(1) << i) - 1) >> j, _nrbits=i - j) + res = modbv((self._val & (1 << i) - 1) >> j, _nrbits=i - j) return res else: i = int(key) diff --git a/myhdl/_util.py b/myhdl/_util.py index 99771b0b..86606639 100644 --- a/myhdl/_util.py +++ b/myhdl/_util.py @@ -29,8 +29,7 @@ import sys import inspect from tokenize import generate_tokens, untokenize, INDENT - -from myhdl._compat import integer_types, StringIO +from io import StringIO def _printExcInfo(): @@ -59,7 +58,7 @@ def _isTupleOfInts(obj): if not isinstance(obj, tuple): return False for e in obj: - if not isinstance(e, integer_types): + if not isinstance(e, int): return False return True diff --git a/myhdl/conversion/_analyze.py b/myhdl/conversion/_analyze.py index 17f0cc0b..61ac8d06 100644 --- a/myhdl/conversion/_analyze.py +++ b/myhdl/conversion/_analyze.py @@ -29,6 +29,7 @@ from types import FunctionType, MethodType import sys import re import ast +import builtins from itertools import chain import myhdl @@ -48,7 +49,6 @@ from myhdl._util import _flatten from myhdl._util import _isTupleOfInts from myhdl._util import _makeAST from myhdl._resolverefs import _AttrRefTransformer -from myhdl._compat import builtins, integer_types, PY2 myhdlObjects = myhdl.__dict__.values() builtinObjects = builtins.__dict__.values() @@ -590,7 +590,7 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin): node.obj = int(0) # XXX elif f is bool: node.obj = bool() - elif f in _flatten(integer_types): + elif f is int: node.obj = int(-1) # elif f in (posedge , negedge): # # node.obj = _EdgeDetector() @@ -628,7 +628,7 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin): if f.__code__.co_freevars: for n, c in zip(f.__code__.co_freevars, f.__closure__): obj = c.cell_contents - if not isinstance(obj, (integer_types, _Signal)): + if not isinstance(obj, (int, _Signal)): self.raiseError(node, _error.FreeVarTypeError, n) tree.symdict[n] = obj v = _FirstPassVisitor(tree) @@ -671,7 +671,7 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin): val = arg.obj if isinstance(val, bool): val = int(val) # cast bool to int first - if isinstance(val, (EnumItemType, integer_types)): + if isinstance(val, (EnumItemType, int)): node.case = (node.left, val) # check whether it can be part of an edge check n = node.left.id @@ -898,12 +898,7 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin): nr = 0 a = [] - if PY2 and isinstance(node, ast.Print): - node_args = node.values - else: - node_args = node.args - - for n in node_args: + for n in node.args: if isinstance(n, ast.BinOp) and isinstance(n.op, ast.Mod) and \ isinstance(n.left, ast.Str): if isinstance(n.right, ast.Tuple): diff --git a/myhdl/conversion/_misc.py b/myhdl/conversion/_misc.py index ebdea1e3..427e31c7 100644 --- a/myhdl/conversion/_misc.py +++ b/myhdl/conversion/_misc.py @@ -26,7 +26,6 @@ from __future__ import absolute_import import ast from myhdl import ConversionError -from myhdl._compat import PY2 class _error(object): @@ -220,7 +219,4 @@ class _namesVisitor(ast.NodeVisitor): def _get_argnames(node): - if PY2: - return [arg.id for arg in node.args.args] - else: - return [arg.arg for arg in node.args.args] + return [arg.arg for arg in node.args.args] diff --git a/myhdl/conversion/_toVHDL.py b/myhdl/conversion/_toVHDL.py index e62be20c..aebb9058 100644 --- a/myhdl/conversion/_toVHDL.py +++ b/myhdl/conversion/_toVHDL.py @@ -36,6 +36,7 @@ from types import GeneratorType import warnings from copy import copy import string +from io import StringIO # import myhdl import myhdl @@ -54,7 +55,6 @@ from myhdl._concat import concat from myhdl._delay import delay from myhdl._misc import downrange from myhdl._util import _flatten -from myhdl._compat import integer_types, class_types, StringIO from myhdl._ShadowSignal import _TristateSignal, _TristateDriver from myhdl._block import _Block from myhdl._getHierarchy import _getHierarchy @@ -1108,7 +1108,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): node.args[0].s = v self.write(v) return - elif f in integer_types: + elif f is int: opening, closing = '', '' pre, suf = self.inferCast(node.vhd, node.vhdOri) # convert number argument to integer @@ -1138,7 +1138,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): self.write(closing) self.write(suf) return - elif (type(f) in class_types) and issubclass(f, Exception): + elif (type(f) in (type,)) and issubclass(f, Exception): self.write(f.__name__) elif f in (posedge, negedge): opening, closing = ' ', '' @@ -1456,7 +1456,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): s = "'%s'" % int(obj) else: s = "%s" % obj - elif isinstance(obj, integer_types): + elif isinstance(obj, int): if isinstance(node.vhd, vhd_int): s = self.IntRepr(obj) elif isinstance(node.vhd, vhd_boolean): @@ -1484,7 +1484,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): s = m.name elif isinstance(obj, EnumItemType): s = obj._toVHDL() - elif (type(obj) in class_types) and issubclass(obj, Exception): + elif (type(obj) in (type,)) and issubclass(obj, Exception): s = n else: self.raiseError(node, _error.UnsupportedType, "%s, %s" % (n, type(obj))) @@ -2149,7 +2149,7 @@ def inferVhdlObj(obj): else: tipe = obj._type vhd = vhd_enum(tipe) - elif isinstance(obj, integer_types): + elif isinstance(obj, int): if obj >= 0: vhd = vhd_nat() else: @@ -2216,7 +2216,7 @@ class _AnnotateTypesVisitor(ast.NodeVisitor, _ConversionMixin): node.vhd = vhd_unsigned(s) elif f is bool: node.vhd = vhd_boolean() - elif f in _flatten(integer_types, ord): + elif f in (int, ord): node.vhd = vhd_int() node.args[0].vhd = vhd_int() elif f in (intbv, modbv): diff --git a/myhdl/conversion/_toVerilog.py b/myhdl/conversion/_toVerilog.py index 0e32cbe1..11e14f95 100644 --- a/myhdl/conversion/_toVerilog.py +++ b/myhdl/conversion/_toVerilog.py @@ -33,14 +33,13 @@ import inspect from datetime import datetime import ast import string +from io import StringIO from types import GeneratorType -from myhdl._compat import StringIO import warnings import myhdl from myhdl import * -from myhdl._compat import integer_types, class_types, PY2 from myhdl import ToVerilogError, ToVerilogWarning from myhdl._extractHierarchy import (_HierExtr, _isMem, _getMemInfo, _UserVerilogCode, _userCodeMap) @@ -835,7 +834,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): elif f is ord: opening, closing = '', '' node.args[0].s = str(ord(node.args[0].s)) - elif f in integer_types: + elif f is int: opening, closing = '', '' # convert number argument to integer if isinstance(node.args[0], ast.Num): @@ -851,7 +850,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): self.write(opening) self.visit(fn.value) self.write(closing) - elif (type(f) in class_types) and issubclass(f, Exception): + elif (type(f) in (type,)) and issubclass(f, Exception): self.write(f.__name__) elif f in (posedge, negedge): opening, closing = ' ', '' @@ -1093,10 +1092,6 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): def getName(self, node): n = node.id - if PY2 and n in ('True', 'False', 'None'): - self.visit_NameConstant(node) - return - addSignBit = False isMixedExpr = (not node.signed) and (self.context == _context.SIGNED) if n in self.tree.vardict: @@ -1110,7 +1105,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): obj = self.tree.symdict[n] if isinstance(obj, bool): s = "1'b%s" % int(obj) - elif isinstance(obj, integer_types): + elif isinstance(obj, int): s = self.IntRepr(obj) elif isinstance(obj, _Signal): addSignBit = isMixedExpr @@ -1121,7 +1116,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin): s = m.name elif isinstance(obj, EnumItemType): s = obj._toVerilog() - elif (type(obj) in class_types) and issubclass(obj, Exception): + elif (type(obj) in (type,)) and issubclass(obj, Exception): s = n else: self.raiseError(node, _error.UnsupportedType, "%s, %s" % (n, type(obj))) @@ -1535,7 +1530,7 @@ class _ConvertTaskVisitor(_ConvertVisitor): def _maybeNegative(obj): if hasattr(obj, '_min') and (obj._min is not None) and (obj._min < 0): return True - if isinstance(obj, integer_types) and obj < 0: + if isinstance(obj, int) and obj < 0: return True return False diff --git a/myhdl/test/conftest.py b/myhdl/test/conftest.py index 2accff93..bac189a5 100644 --- a/myhdl/test/conftest.py +++ b/myhdl/test/conftest.py @@ -1,5 +1,3 @@ -import sys - import py import pytest @@ -10,8 +8,7 @@ xfail = pytest.mark.xfail all_sims = list(_simulators) -if sys.version_info[0] > 2: - collect_ignore = ['conversion/toVerilog/test_not_supported_py2.py'] +collect_ignore = ['conversion/toVerilog/test_not_supported_py2.py'] def pytest_addoption(parser): parser.addoption("--sim", action="store", choices=all_sims, diff --git a/myhdl/test/core/test_Cosimulation.py b/myhdl/test/core/test_Cosimulation.py index 25e6d9b8..4a9dbffb 100644 --- a/myhdl/test/core/test_Cosimulation.py +++ b/myhdl/test/core/test_Cosimulation.py @@ -29,7 +29,6 @@ if sys.platform == "win32": import msvcrt from myhdl import Signal -from myhdl._compat import to_bytes from myhdl._Cosimulation import Cosimulation, CosimulationError, _error if __name__ != '__main__': @@ -90,7 +89,7 @@ class TestCosimulation: buf = "FROM 00 " for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) os.write(wt, b"TO 0000 a 1") os.read(rf, MAXLINE) @@ -110,7 +109,7 @@ class TestCosimulation: buf = "TO 00 " for s, w in zip(toSignames, toSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) os.write(wt, b"FROM 0000") os.read(rf, MAXLINE) @@ -130,12 +129,12 @@ class TestCosimulation: buf = "FROM 00 " for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) buf = "TO 00 " for s, w in zip(toSignames, toSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) os.write(wt, b"START") os.read(rf, MAXLINE) @@ -150,7 +149,7 @@ class TestCosimulation: buf = "TO 01 " for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) def testNoComm(self): with raises_kind(CosimulationError, _error.NoCommunication): @@ -177,7 +176,7 @@ class TestCosimulation: for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) buf += "bb 5" - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) def testToSignalsDupl(self): with raises_kind(CosimulationError, _error.DuplicateSigNames): @@ -190,7 +189,7 @@ class TestCosimulation: for s, w in zip(toSignames, toSizes): buf += "%s %s " % (s, w) buf += "fff 6" - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) def testFromSignalVals(self): cosim = Cosimulation(exe + "cosimFromSignalVals", **allSigs) @@ -204,7 +203,7 @@ class TestCosimulation: buf = "FROM 00 " for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) os.write(wt, b"TO 0000 a 1") os.read(rf, MAXLINE) @@ -234,12 +233,12 @@ class TestCosimulation: buf = "FROM 00 " for s, w in zip(fromSignames, fromSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) buf = "TO 00 " for s, w in zip(toSignames, toSizes): buf += "%s %s " % (s, w) - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) os.write(wt, b"START") os.read(rf, MAXLINE) @@ -249,7 +248,7 @@ class TestCosimulation: buf += " " buf += hex(v)[2:] buf += " " - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) os.read(rf, MAXLINE) buf = "0 " for s, v in zip(toSignames, toXVals): @@ -257,7 +256,7 @@ class TestCosimulation: buf += " " buf += v buf += " " - os.write(wt, to_bytes(buf)) + os.write(wt, buf.encode()) if __name__ == "__main__": getattr(TestCosimulation, sys.argv[1])() diff --git a/myhdl/test/core/test_ShadowSignal.py b/myhdl/test/core/test_ShadowSignal.py index d271598e..1f936194 100644 --- a/myhdl/test/core/test_ShadowSignal.py +++ b/myhdl/test/core/test_ShadowSignal.py @@ -2,7 +2,6 @@ from __future__ import absolute_import import myhdl from myhdl import * -from myhdl._compat import long def bench_SliceSignal(): @@ -114,9 +113,9 @@ def bench_ConcatSignalWithConsts(): d.next = m e.next = n yield delay(10) - assert s[29:27] == long(c1, 2) + assert s[29:27] == int(c1, 2) assert s[27:22] == a - assert s[21] == long(c2, 2) + assert s[21] == int(c2, 2) assert s[20] == b assert s[20:17] == c3 assert s[17:14] == c diff --git a/myhdl/test/core/test_Signal.py b/myhdl/test/core/test_Signal.py index 1da94f2e..8df01d71 100644 --- a/myhdl/test/core/test_Signal.py +++ b/myhdl/test/core/test_Signal.py @@ -29,7 +29,6 @@ from random import randrange import pytest from myhdl import Signal, intbv -from myhdl._compat import long from myhdl._simulator import _siglist random.seed(1) # random, but deterministic @@ -107,8 +106,8 @@ class TestSig: for s in (self.sigs + self.incompatibleSigs): for n in (self.vals + self.incompatibleVals): assert isinstance(s.val, s._type) - if isinstance(s.val, (int, long, intbv)): - t = (int, long, intbv) + if isinstance(s.val, (int, intbv)): + t = (int, intbv) else: t = s._type if not isinstance(n, t): @@ -261,11 +260,11 @@ class TestSignalAsNum: def binaryCheck(self, op, imin=0, imax=None, jmin=0, jmax=None): self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax) for i, j in zip(self.seqi, self.seqj): - bi = Signal(long(i)) - bj = Signal(long(j)) - ref = op(long(i), j) + bi = Signal(int(i)) + bj = Signal(int(j)) + ref = op(int(i), j) r1 = op(bi, j) - r2 = op(long(i), bj) + r2 = op(int(i), bj) r3 = op(bi, bj) assert type(r1) == type(ref) assert type(r2) == type(ref) @@ -278,13 +277,13 @@ class TestSignalAsNum: self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax) for i, j in zip(self.seqi, self.seqj): bj = Signal(j) - ref = long(i) + ref = int(i) ref = op(ref, j) r1 = bi1 = Signal(i) with pytest.raises(TypeError): r1 = op(r1, j) - r2 = long(i) + r2 = int(i) r2 = op(r2, bj) r3 = bi3 = Signal(i) with pytest.raises(TypeError): @@ -405,7 +404,7 @@ class TestSignalAsNum: self.conversionCheck(int, imax=maxint) def testLong(self): - self.conversionCheck(long) + self.conversionCheck(int) def testFloat(self): self.conversionCheck(float) @@ -469,11 +468,11 @@ class TestSignalIntBvIndexing: def testGetItem(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) sbv = Signal(intbv(n)) sbvi = Signal(intbv(~n)) for i in range(len(s)+20): - ref = long(getItem(s, i), 2) + ref = int(getItem(s, i), 2) res = sbv[i] resi = sbvi[i] assert res == ref @@ -484,7 +483,7 @@ class TestSignalIntBvIndexing: def testGetSlice(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) sbv = Signal(intbv(n)) sbvi = Signal(intbv(~n)) for i in range(1, len(s)+20): @@ -495,7 +494,7 @@ class TestSignalIntBvIndexing: except ValueError: assert i<=j continue - ref = long(getSlice(s, i, j), 2) + ref = int(getSlice(s, i, j), 2) assert res == ref assert type(res) == intbv mask = (2**(i-j))-1 diff --git a/myhdl/test/core/test_bin.py b/myhdl/test/core/test_bin.py index 1db13ae4..ca02bc6d 100644 --- a/myhdl/test/core/test_bin.py +++ b/myhdl/test/core/test_bin.py @@ -25,7 +25,6 @@ import sys from random import randrange from myhdl import bin -from myhdl._compat import long random.seed(1) # random, but deterministic @@ -48,7 +47,7 @@ def binref(num, width=0): Optional parameter: width -- specifies the desired string (sign bit padding) """ - num = long(num) + num = int(num) s = _int2bitstring(num) if width: pad = '0' diff --git a/myhdl/test/core/test_concat.py b/myhdl/test/core/test_concat.py index 31e4cd2b..bb2c9b2b 100644 --- a/myhdl/test/core/test_concat.py +++ b/myhdl/test/core/test_concat.py @@ -26,7 +26,6 @@ from functools import reduce import pytest -from myhdl._compat import long from myhdl._concat import concat from myhdl._intbv import intbv from myhdl._Signal import Signal @@ -49,7 +48,7 @@ class TestConcat: bv = concat(base, *exts) refstr = basestr + reduce(operator.add, extstr) reflen = len(refstr) - ref = long(refstr, 2) + ref = int(refstr, 2) assert bv == ref assert len(bv) == reflen @@ -58,7 +57,7 @@ class TestConcat: for exts, extstr in zip(extslist, self.extslist): bv = concat(base, *exts) refstr = basestr + reduce(operator.add, extstr) - ref = long(refstr, 2) + ref = int(refstr, 2) assert bv == ref assert len(bv) == 0 @@ -68,12 +67,12 @@ class TestConcat: self.ConcatToSizedBase(bases, extslist) def testConcatStringsToInt(self): - bases = [long(base, 2) for base in self.bases] + bases = [int(base, 2) for base in self.bases] extslist = self.extslist self.ConcatToUnsizedBase(bases, extslist) def testConcatStringsToSignalInt(self): - bases = [Signal(long(base, 2)) for base in self.bases] + bases = [Signal(int(base, 2)) for base in self.bases] extslist = self.extslist self.ConcatToUnsizedBase(bases, extslist) @@ -140,28 +139,28 @@ class TestConcat: self.ConcatToSizedBase(bases, extslist) def testConcatIntbvsToInt(self): - bases = [long(base, 2) for base in self.bases] + bases = [int(base, 2) for base in self.bases] extslist = [] for exts in self.extslist: extslist.append([intbv(ext) for ext in exts]) self.ConcatToUnsizedBase(bases, extslist) def testConcatSignalIntbvsToInt(self): - bases = [long(base, 2) for base in self.bases] + bases = [int(base, 2) for base in self.bases] extslist = [] for exts in self.extslist: extslist.append([Signal(intbv(ext)) for ext in exts]) self.ConcatToUnsizedBase(bases, extslist) def testConcatIntbvsToSignalInt(self): - bases = [Signal(long(base, 2)) for base in self.bases] + bases = [Signal(int(base, 2)) for base in self.bases] extslist = [] for exts in self.extslist: extslist.append([intbv(ext) for ext in exts]) self.ConcatToUnsizedBase(bases, extslist) def testConcatSignalIntbvsToSignalInt(self): - bases = [Signal(long(base, 2)) for base in self.bases] + bases = [Signal(int(base, 2)) for base in self.bases] extslist = [] for exts in self.extslist: extslist.append([Signal(intbv(ext)) for ext in exts]) @@ -199,7 +198,7 @@ class TestConcat: def testConcatMixToUnsizedBase(self): bases = [] for base in self.bases: - seq = (long(base, 2), Signal(long(base, 2))) + seq = (int(base, 2), Signal(int(base, 2))) bases.append(random.choice(seq)) extslist = [] for exts in self.extslist: diff --git a/myhdl/test/core/test_intbv.py b/myhdl/test/core/test_intbv.py index e771acea..689e3dcc 100644 --- a/myhdl/test/core/test_intbv.py +++ b/myhdl/test/core/test_intbv.py @@ -28,7 +28,6 @@ from random import randrange import pytest -from myhdl._compat import integer_types, long from myhdl._intbv import intbv random.seed(2) # random, but deterministic @@ -105,11 +104,11 @@ class TestIntBvIndexing: def testGetItem(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) bv = intbv(n) bvi = intbv(~n) for i in range(len(s)+20): - ref = long(getItem(s, i), 2) + ref = int(getItem(s, i), 2) res = bv[i] resi = bvi[i] assert res == ref @@ -120,7 +119,7 @@ class TestIntBvIndexing: def testGetSlice(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) bv = intbv(n) bvi = intbv(~n) for i in range(1, len(s)+20): @@ -131,7 +130,7 @@ class TestIntBvIndexing: except ValueError: assert i<=j continue - ref = long(getSlice(s, i, j), 2) + ref = int(getSlice(s, i, j), 2) assert res == ref assert type(res) == intbv mask = (2**(i-j))-1 @@ -141,13 +140,13 @@ class TestIntBvIndexing: def testGetSliceLeftOpen(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) bv = intbv(n) bvi = intbv(~n) for j in range(0,len(s)+20): res = bv[:j] resi = bvi[:j] - ref = long(getSliceLeftOpen(s, j), 2) + ref = int(getSliceLeftOpen(s, j), 2) assert res == ref assert type(res) == intbv assert resi+ref == -1 @@ -156,7 +155,7 @@ class TestIntBvIndexing: def testSetItem(self): self.seqsSetup() for s in self.seqs: - n = long(s, 2) + n = int(s, 2) for it in (int, intbv): for i in range(len(s)+20): # print i @@ -168,10 +167,10 @@ class TestIntBvIndexing: bv1[i] = it(1) bv0i[i] = it(0) bv1i[i] = it(1) - ref0 = long(setItem(s, i, '0'), 2) - ref1 = long(setItem(s, i, '1'), 2) - ref0i = ~long(setItem(s, i, '1'), 2) - ref1i = ~long(setItem(s, i, '0'), 2) + ref0 = int(setItem(s, i, '0'), 2) + ref1 = int(setItem(s, i, '1'), 2) + ref0i = ~int(setItem(s, i, '1'), 2) + ref1i = ~int(setItem(s, i, '0'), 2) assert bv0 == ref0 assert bv1 == ref1 assert bv0i == ref0i @@ -181,7 +180,7 @@ class TestIntBvIndexing: self.seqsSetup() toggle = 0 for s in self.seqs: - n = long(s, 2) + n = int(s, 2) for i in range(1, len(s)+5): for j in range(0, len(s)+5): for v in self.seqv: @@ -189,7 +188,7 @@ class TestIntBvIndexing: extv = ext + v bv = intbv(n) bvi = intbv(~n) - val = long(v, 2) + val = int(v, 2) toggle ^= 1 if toggle: val = intbv(val) @@ -199,7 +198,7 @@ class TestIntBvIndexing: assert i<=j or val >= 2**(i-j) continue else: - ref = long(setSlice(s, i, j, extv), 2) + ref = int(setSlice(s, i, j, extv), 2) assert bv == ref mask = (2**(i-j))-1 vali = val ^ mask @@ -209,27 +208,27 @@ class TestIntBvIndexing: assert vali >= 2**(i-j) continue else: - refi = ~long(setSlice(s, i, j, extv), 2) + refi = ~int(setSlice(s, i, j, extv), 2) assert bvi == refi def testSetSliceLeftOpen(self): self.seqsSetup() toggle = 0 for s in self.seqs: - n = long(s, 2) + n = int(s, 2) for j in range(0, len(s)+5): for v in self.seqv: bv = intbv(n) bvi = intbv(~n) - val = long(v, 2) + val = int(v, 2) toggle ^= 1 if toggle: val = intbv(val) bv[:j] = val bvi[:j] = -1-val - ref = long(setSliceLeftOpen(s, j, v), 2) + ref = int(setSliceLeftOpen(s, j, v), 2) assert bv == ref - refi = ~long(setSliceLeftOpen(s, j, v), 2) + refi = ~int(setSliceLeftOpen(s, j, v), 2) assert bvi == refi @@ -253,7 +252,7 @@ class TestIntBvAsInt: j = randrange(jmin, jfirstmax) seqi.append(i) seqj.append(j) - # then some potentially longs + # then some potentially ints for n in range(100): if not imax: i = randrange(maxint) + randrange(maxint) @@ -271,11 +270,11 @@ class TestIntBvAsInt: def binaryCheck(self, op, imin=0, imax=None, jmin=0, jmax=None): self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax) for i, j in zip(self.seqi, self.seqj): - bi = intbv(long(i)) + bi = intbv(int(i)) bj = intbv(j) - ref = op(long(i), j) + ref = op(int(i), j) r1 = op(bi, j) - r2 = op(long(i), bj) + r2 = op(int(i), bj) r3 = op(bi, bj) #self.assertEqual(type(r1), intbv) #self.assertEqual(type(r2), intbv) @@ -288,13 +287,13 @@ class TestIntBvAsInt: self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax) for i, j in zip(self.seqi, self.seqj): bj = intbv(j) - ref = long(i) + ref = int(i) ref = op(ref, j) - r1 = bi1 = intbv(long(i)) + r1 = bi1 = intbv(int(i)) r1 = op(r1, j) - r2 = long(i) + r2 = int(i) r2 = op(r2, bj) - r3 = bi3 = intbv(long(i)) + r3 = bi3 = intbv(int(i)) r3 = op(r3, bj) assert type(r1) == intbv assert type(r3) == intbv @@ -420,7 +419,7 @@ class TestIntBvAsInt: self.conversionCheck(int, imax=maxint) def testLong(self): - self.conversionCheck(long) + self.conversionCheck(int) def testFloat(self): self.conversionCheck(float) @@ -486,10 +485,10 @@ class TestIntbvBounds: a = intbv(i) assert a == i # just to be sure try: - exec("a %s long(j)" % op) + exec("a %s int(j)" % op) except (ZeroDivisionError, ValueError): return # prune - if not isinstance(a._val, integer_types): + if not isinstance(a._val, int): return # prune if abs(a) > maxint * maxint: return # keep it reasonable @@ -498,17 +497,17 @@ class TestIntbvBounds: for m in (i+1, a): b = intbv(i, min=i, max=m) with pytest.raises(ValueError): - exec("b %s long(j)" % op) + exec("b %s int(j)" % op) elif a < i : b = intbv(i, min=a, max=i+1) - exec("b %s long(j)" % op) # should be ok + exec("b %s int(j)" % op) # should be ok for m in (a+1, i): b = intbv(i, min=m, max=i+1) with pytest.raises(ValueError): - exec("b %s long(j)" % op) + exec("b %s int(j)" % op) else: # a == i b = intbv(i, min=i, max=i+1) - exec("b %s long(j)" % op) # should be ok + exec("b %s int(j)" % op) # should be ok def checkOp(self, op): for i in (0, 1, -1, 2, -2, 16, -24, 129, -234, 1025, -15660): diff --git a/myhdl/test/core/test_modbv.py b/myhdl/test/core/test_modbv.py index 201d5049..69e4897a 100644 --- a/myhdl/test/core/test_modbv.py +++ b/myhdl/test/core/test_modbv.py @@ -29,7 +29,6 @@ from random import randrange from myhdl._intbv import intbv from myhdl._modbv import modbv -from myhdl._compat import integer_types, long random.seed(3) maxint=sys.maxsize diff --git a/setup.py b/setup.py index 7e6d6b16..4faec8a8 100644 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ import sys from collections import defaultdict -if sys.version_info < (2, 6) or (3, 0) <= sys.version_info < (3, 4): - raise RuntimeError("Python version 2.6, 2.7 or >= 3.4 required.") +if sys.version_info < (3, 4): + raise RuntimeError("Python version 3.4+ required.") # Prefer setuptools over distutils @@ -53,10 +53,11 @@ setup( 'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3 :: Only', ] ) diff --git a/tox.ini b/tox.ini index 75301868..e587a6af 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py34 +envlist = py34 [testenv] deps = pytest-xdist