diff options
author | Seth Troisi <sethtroisi@google.com> | 2020-01-15 17:03:58 -0800 |
---|---|---|
committer | Seth Troisi <sethtroisi@google.com> | 2020-01-20 15:22:57 -0800 |
commit | 9a21ec857b22ff0140a7f71a12f2cc943f163404 (patch) | |
tree | 1f8b26a1bb346fab26d2210de286d29011bf2bf1 /numpy/core | |
parent | b753aa7a3a2c958e70826fb8af3b56db5c758819 (diff) | |
download | numpy-9a21ec857b22ff0140a7f71a12f2cc943f163404.tar.gz |
[MAINT] Cleanup python2 sys.version checks
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/__init__.py | 7 | ||||
-rw-r--r-- | numpy/core/arrayprint.py | 15 | ||||
-rw-r--r-- | numpy/core/code_generators/generate_umath.py | 20 | ||||
-rw-r--r-- | numpy/core/defchararray.py | 4 | ||||
-rw-r--r-- | numpy/core/numeric.py | 6 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 8 | ||||
-rw-r--r-- | numpy/core/setup_common.py | 6 |
7 files changed, 17 insertions, 49 deletions
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py index 815c61924..c2d53fe3e 100644 --- a/numpy/core/__init__.py +++ b/numpy/core/__init__.py @@ -135,16 +135,11 @@ def _ufunc_reduce(func): return _ufunc_reconstruct, (whichmodule(func, name), name) -import sys -if sys.version_info[0] >= 3: - import copyreg -else: - import copy_reg as copyreg +import copyreg copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct) # Unclutter namespace (must keep _ufunc_reconstruct for unpickling) del copyreg -del sys del _ufunc_reduce from numpy._pytesttester import PytestTester diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 918da4a72..ec7e4261f 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -22,19 +22,12 @@ __docformat__ = 'restructuredtext' # scalars are printed inside an ndarray. Only the latter strs are currently # user-customizable. -import sys import functools import numbers -if sys.version_info[0] >= 3: - try: - from _thread import get_ident - except ImportError: - from _dummy_thread import get_ident -else: - try: - from thread import get_ident - except ImportError: - from dummy_thread import get_ident +try: + from _thread import get_ident +except ImportError: + from _dummy_thread import get_ident import numpy as np from . import numerictypes as _nt diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index f5691d950..7599360f5 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -148,12 +148,8 @@ class Ufunc: # String-handling utilities to avoid locale-dependence. import string -if sys.version_info[0] < 3: - UPPER_TABLE = string.maketrans(string.ascii_lowercase, - string.ascii_uppercase) -else: - UPPER_TABLE = bytes.maketrans(bytes(string.ascii_lowercase, "ascii"), - bytes(string.ascii_uppercase, "ascii")) +UPPER_TABLE = bytes.maketrans(bytes(string.ascii_lowercase, "ascii"), + bytes(string.ascii_uppercase, "ascii")) def english_upper(s): """ Apply English case rules to convert ASCII strings to all upper case. @@ -1076,15 +1072,9 @@ def make_ufuncs(funcdict): uf = funcdict[name] mlist = [] docstring = textwrap.dedent(uf.docstring).strip() - if sys.version_info[0] < 3: - docstring = docstring.encode('string-escape') - docstring = docstring.replace(r'"', r'\"') - else: - docstring = docstring.encode('unicode-escape').decode('ascii') - docstring = docstring.replace(r'"', r'\"') - # XXX: I don't understand why the following replace is not - # necessary in the python 2 case. - docstring = docstring.replace(r"'", r"\'") + docstring = docstring.encode('unicode-escape').decode('ascii') + docstring = docstring.replace(r'"', r'\"') + docstring = docstring.replace(r"'", r"\'") # Split the docstring because some compilers (like MS) do not like big # string literal in C code. We split at endlines because textwrap.wrap # do not play well with \n diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py index 4d7781317..1cfdc55c0 100644 --- a/numpy/core/defchararray.py +++ b/numpy/core/defchararray.py @@ -1953,8 +1953,8 @@ class chararray(ndarray): # strings in the new array. itemsize = long(itemsize) - if sys.version_info[0] >= 3 and isinstance(buffer, str): - # On Py3, unicode objects do not have the buffer interface + if isinstance(buffer, str): + # unicode objects do not have the buffer interface filler = buffer buffer = None else: diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 5a1cbe9fc..72c6089b8 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -35,12 +35,6 @@ bitwise_not = invert ufunc = type(sin) newaxis = None -if sys.version_info[0] >= 3: - import builtins -else: - import __builtin__ as builtins - - array_function_dispatch = functools.partial( overrides.array_function_dispatch, module='numpy') diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index c63ea08c7..c06552c4e 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -80,7 +80,6 @@ Exported symbols include: """ import types as _types -import sys import numbers import warnings @@ -120,11 +119,8 @@ from ._dtype import _kind_name # we don't export these for import *, but we do want them accessible # as numerictypes.bool, etc. -if sys.version_info[0] >= 3: - from builtins import bool, int, float, complex, object, str - unicode = str -else: - from __builtin__ import bool, int, float, complex, object, unicode, str +from builtins import bool, int, float, complex, object, str +unicode = str # We use this later diff --git a/numpy/core/setup_common.py b/numpy/core/setup_common.py index a947f7a3d..6d8e603a7 100644 --- a/numpy/core/setup_common.py +++ b/numpy/core/setup_common.py @@ -244,9 +244,9 @@ def check_long_double_representation(cmd): # Disable multi-file interprocedural optimization in the Intel compiler on Linux # which generates intermediary object files and prevents checking the # float representation. - elif (sys.platform != "win32" - and cmd.compiler.compiler_type.startswith('intel') - and '-ipo' in cmd.compiler.cc_exe): + elif (sys.platform != "win32" + and cmd.compiler.compiler_type.startswith('intel') + and '-ipo' in cmd.compiler.cc_exe): newcompiler = cmd.compiler.cc_exe.replace(' -ipo', '') cmd.compiler.set_executables( compiler=newcompiler, |