summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSeth Troisi <sethtroisi@google.com>2020-01-15 17:03:58 -0800
committerSeth Troisi <sethtroisi@google.com>2020-01-20 15:22:57 -0800
commit9a21ec857b22ff0140a7f71a12f2cc943f163404 (patch)
tree1f8b26a1bb346fab26d2210de286d29011bf2bf1 /tools
parentb753aa7a3a2c958e70826fb8af3b56db5c758819 (diff)
downloadnumpy-9a21ec857b22ff0140a7f71a12f2cc943f163404.tar.gz
[MAINT] Cleanup python2 sys.version checks
Diffstat (limited to 'tools')
-rwxr-xr-xtools/changelog.py6
-rw-r--r--tools/npy_tempita/__init__.py11
-rw-r--r--tools/npy_tempita/_looper.py6
-rw-r--r--tools/refguide_check.py22
4 files changed, 15 insertions, 30 deletions
diff --git a/tools/changelog.py b/tools/changelog.py
index 00ffdd9eb..2a0c4da43 100755
--- a/tools/changelog.py
+++ b/tools/changelog.py
@@ -36,13 +36,11 @@ From the bash command line with $GITHUB token::
import os
import sys
import re
-import codecs
from git import Repo
from github import Github
-if sys.version_info.major < 3:
- UTF8Writer = codecs.getwriter('utf8')
- sys.stdout = UTF8Writer(sys.stdout)
+if sys.version_info[:2] < (3, 6):
+ raise RuntimeError("Python version must be >= 3.6")
this_repo = Repo(os.path.join(os.path.dirname(__file__), ".."))
diff --git a/tools/npy_tempita/__init__.py b/tools/npy_tempita/__init__.py
index b84754988..ec4b0d5e7 100644
--- a/tools/npy_tempita/__init__.py
+++ b/tools/npy_tempita/__init__.py
@@ -317,7 +317,7 @@ class Template:
arg0 = e_value.args[0]
else:
arg0 = coerce_text(e_value)
- e_value.args = (self._add_line_info(arg0, pos),)
+ e_value.args = (self._add_line_info(arg0, pos),)
if PY3:
raise e_value
else:
@@ -461,14 +461,11 @@ def html_quote(value, force=True):
return ''
if not isinstance(value, basestring_):
value = coerce_text(value)
- if sys.version >= "3" and isinstance(value, bytes):
+ if isinstance(value, bytes):
value = html_escape(value.decode('latin1'), 1)
value = value.encode('latin1')
else:
value = html_escape(value, 1)
- if sys.version < "3":
- if is_unicode(value):
- value = value.encode('ascii', 'xmlcharrefreplace')
return value
@@ -1286,7 +1283,7 @@ def fill_command(args=None):
template_content = sys.stdin.read()
template_name = '<stdin>'
else:
- with open(template_name, 'rb', encoding="latin-1") as f:
+ with open(template_name, 'rb', encoding="latin-1") as f:
template_content = f.read()
if options.use_html:
TemplateClass = HTMLTemplate
@@ -1295,7 +1292,7 @@ def fill_command(args=None):
template = TemplateClass(template_content, name=template_name)
result = template.substitute(vars)
if options.output:
- with open(options.output, 'wb') as f:
+ with open(options.output, 'wb') as f:
f.write(result)
else:
sys.stdout.write(result)
diff --git a/tools/npy_tempita/_looper.py b/tools/npy_tempita/_looper.py
index 23121fe9e..8a1156678 100644
--- a/tools/npy_tempita/_looper.py
+++ b/tools/npy_tempita/_looper.py
@@ -61,9 +61,6 @@ class looper_iter:
self.pos += 1
return result
- if sys.version < "3":
- next = __next__
-
class loop_pos:
@@ -94,9 +91,6 @@ class loop_pos:
except IndexError:
return None
- if sys.version < "3":
- next = __next__
-
@property
def previous(self):
if self.pos == 0:
diff --git a/tools/refguide_check.py b/tools/refguide_check.py
index 3b587b77b..ad3f93c42 100644
--- a/tools/refguide_check.py
+++ b/tools/refguide_check.py
@@ -195,7 +195,7 @@ def find_names(module, names_dict):
names_dict : dict
Dictionary which contains module name as key and a set of found
function names and directives as value
-
+
Returns
-------
None
@@ -229,12 +229,12 @@ def find_names(module, names_dict):
def get_all_dict(module):
"""
Return a copy of the __all__ dict with irrelevant items removed.
-
+
Parameters
----------
module : ModuleType
The module whose __all__ dict has to be processed
-
+
Returns
-------
deprecated : list
@@ -242,7 +242,7 @@ def get_all_dict(module):
not_deprecated : list
List of non callable or non deprecated sub modules
others : list
- List of remaining types of sub modules
+ List of remaining types of sub modules
"""
if hasattr(module, "__all__"):
all_dict = copy.deepcopy(module.__all__)
@@ -863,7 +863,7 @@ def check_doctests(module, verbose, ns=None,
ns : dict
Name space of module
dots : bool
-
+
doctest_warnings : bool
Returns
@@ -934,7 +934,7 @@ def check_doctests_testfile(fname, verbose, ns=None,
ns : dict
Name space
-
+
dots : bool
doctest_warnings : bool
@@ -978,12 +978,8 @@ def check_doctests_testfile(fname, verbose, ns=None,
return results
full_name = fname
- if sys.version_info.major <= 2:
- with open(fname) as f:
- text = f.read()
- else:
- with open(fname, encoding='utf-8') as f:
- text = f.read()
+ with open(fname, encoding='utf-8') as f:
+ text = f.read()
PSEUDOCODE = set(['some_function', 'some_module', 'import example',
'ctypes.CDLL', # likely need compiling, skip it
@@ -1116,7 +1112,7 @@ def init_matplotlib():
def main(argv):
"""
Validates the docstrings of all the pre decided set of
- modules for errors and docstring standards.
+ modules for errors and docstring standards.
"""
parser = ArgumentParser(usage=__doc__.lstrip())
parser.add_argument("module_names", metavar="SUBMODULES", default=[],