From 24804a3942ff1db150f005dbabeb60afd1a98f43 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Mon, 7 Sep 2020 10:45:43 -0500
Subject: [PATCH] Placate flake8 quotes linter

---
 pytools/__init__.py           | 40 +++++++++++++++++------------------
 pytools/debug.py              |  2 +-
 pytools/importlib_backport.py |  8 +++----
 pytools/log.py                |  2 +-
 pytools/persistent_dict.py    |  8 +++----
 setup.cfg                     |  4 ++++
 test/test_graph_tools.py      | 26 +++++++++++------------
 7 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/pytools/__init__.py b/pytools/__init__.py
index 4c59783..950e001 100644
--- a/pytools/__init__.py
+++ b/pytools/__init__.py
@@ -169,7 +169,7 @@ Type Variables Used
 # {{{ type variables
 
 T = TypeVar("T")
-F = TypeVar('F', bound=Callable[..., Any])
+F = TypeVar("F", bound=Callable[..., Any])
 
 # }}}
 
@@ -341,7 +341,7 @@ class Record(RecordWithoutPickling):
 
 
 class ImmutableRecordWithoutPickling(RecordWithoutPickling):
-    "Hashable record. Does not explicitly enforce immutability."
+    """Hashable record. Does not explicitly enforce immutability."""
     def __init__(self, *args, **kwargs):
         RecordWithoutPickling.__init__(self, *args, **kwargs)
         self._cached_hash = None
@@ -523,7 +523,7 @@ def memoize(*args: F, **kwargs: Any) -> F:
         which computes and returns the cache key.
     """
 
-    use_kw = bool(kwargs.pop('use_kwargs', False))
+    use_kw = bool(kwargs.pop("use_kwargs", False))
 
     default_key_func: Optional[Callable[..., Any]]
 
@@ -1514,7 +1514,7 @@ class Table:
         if alignments is not None:
             self.alignments = alignments
         else:
-            self.alignments = ['l']
+            self.alignments = ["l"]
 
     def add_row(self, row):
         self.rows.append([str(i) for i in row])
@@ -1572,7 +1572,7 @@ class Table:
 
         """  # noqa: W605
         # Pipe symbols ('|') must be replaced
-        rows = [[w.replace('|', '\\|') for w in r] for r in self.rows]
+        rows = [[w.replace("|", "\\|") for w in r] for r in self.rows]
 
         columns = len(rows[0])
         col_widths = [max(len(row[i]) for row in rows)
@@ -1597,7 +1597,7 @@ class Table:
 
         return "\n".join(lines)
 
-    def csv(self, dialect='excel', csv_kwargs=None):
+    def csv(self, dialect="excel", csv_kwargs=None):
         """Returns a string containing a CSV representation of the table.
 
         :arg dialect: String passed to :func:`csv.writer`.
@@ -1619,15 +1619,15 @@ class Table:
         if csv_kwargs is None:
             csv_kwargs = {}
 
-        # Default is '\r\n'
-        if 'lineterminator' not in csv_kwargs:
-            csv_kwargs['lineterminator'] = '\n'
+        # Default is "\r\n"
+        if "lineterminator" not in csv_kwargs:
+            csv_kwargs["lineterminator"] = "\n"
 
         output = io.StringIO()
         writer = csv.writer(output, dialect, **csv_kwargs)
         writer.writerows(self.rows)
 
-        return output.getvalue().rstrip(csv_kwargs['lineterminator'])
+        return output.getvalue().rstrip(csv_kwargs["lineterminator"])
 
     def latex(self, skip_lines=0, hline_after=None):
         if hline_after is None:
@@ -1706,13 +1706,13 @@ def word_wrap(text, width, wrap_using="\n"):
     breaks are posix newlines (``\n``).
     """
     space_or_break = [" ", wrap_using]
-    return reduce(lambda line, word: '%s%s%s' %
+    return reduce(lambda line, word: "%s%s%s" %
             (line,
-                space_or_break[(len(line)-line.rfind('\n')-1
-                    + len(word.split('\n', 1)[0])
+                space_or_break[(len(line)-line.rfind("\n")-1
+                    + len(word.split("\n", 1)[0])
                     >= width)],
                     word),
-            text.split(' ')
+            text.split(" ")
             )
 
 # }}}
@@ -1723,9 +1723,9 @@ def word_wrap(text, width, wrap_using="\n"):
 def _exec_arg(arg, execenv):
     import os
     if os.access(arg, os.F_OK):
-        exec(compile(open(arg, "r"), arg, 'exec'), execenv)
+        exec(compile(open(arg, "r"), arg, "exec"), execenv)
     else:
-        exec(compile(arg, "<command line>", 'exec'), execenv)
+        exec(compile(arg, "<command line>", "exec"), execenv)
 
 
 class CPyUserInterface(object):
@@ -2187,14 +2187,14 @@ def find_git_revision(tree_root):  # pylint: disable=too-many-locals
     # https://github.com/numpy/numpy/blob/055ce3e90b50b5f9ef8cf1b8641c42e391f10735/setup.py#L70-L92
     import os
     env = {}
-    for k in ['SYSTEMROOT', 'PATH', 'HOME']:
+    for k in ["SYSTEMROOT", "PATH", "HOME"]:
         v = os.environ.get(k)
         if v is not None:
             env[k] = v
     # LANGUAGE is used on win32
-    env['LANGUAGE'] = 'C'
-    env['LANG'] = 'C'
-    env['LC_ALL'] = 'C'
+    env["LANGUAGE"] = "C"
+    env["LANG"] = "C"
+    env["LC_ALL"] = "C"
 
     from subprocess import Popen, PIPE, STDOUT
     p = Popen(["git", "rev-parse", "HEAD"], shell=False,
diff --git a/pytools/debug.py b/pytools/debug.py
index 94490aa..2af8e6b 100644
--- a/pytools/debug.py
+++ b/pytools/debug.py
@@ -147,7 +147,7 @@ def refdebug(obj, top_level=True, exclude=()):  # noqa: E501  pylint:disable=too
 
 def get_shell_hist_filename():
     import os
-    _home = os.environ.get('HOME', '/')
+    _home = os.environ.get("HOME", "/")
     return os.path.join(_home, ".pytools-debug-shell-history")
 
 
diff --git a/pytools/importlib_backport.py b/pytools/importlib_backport.py
index 86dd4c6..0291d42 100644
--- a/pytools/importlib_backport.py
+++ b/pytools/importlib_backport.py
@@ -63,12 +63,12 @@ import six
 
 def _resolve_name(name, package, level):
     """Return the absolute name of the module to be imported."""
-    if not hasattr(package, 'rindex'):
+    if not hasattr(package, "rindex"):
         raise ValueError("'package' not set to a string")
     dot = len(package)
     for _ in six.moves.xrange(level, 1, -1):
         try:
-            dot = package.rindex('.', 0, dot)
+            dot = package.rindex(".", 0, dot)
         except ValueError:
             raise ValueError("attempted relative import beyond top-level "
                              "package")
@@ -81,12 +81,12 @@ def import_module(name, package=None):
     specifies the package to use as the anchor point from which to resolve the
     relative import to an absolute import.
     """
-    if name.startswith('.'):
+    if name.startswith("."):
         if not package:
             raise TypeError("relative imports require the 'package' argument")
         level = 0
         for character in name:
-            if character != '.':
+            if character != ".":
                 break
             level += 1
         name = _resolve_name(name[level:], package, level)
diff --git a/pytools/log.py b/pytools/log.py
index f023b50..5dfb0f5 100644
--- a/pytools/log.py
+++ b/pytools/log.py
@@ -284,7 +284,7 @@ def _get_unique_id():
         rng = Random()
         rng.seed()
         for i in range(20):
-            checksum.update(str(rng.randrange(1 << 30)).encode('utf-32'))
+            checksum.update(str(rng.randrange(1 << 30)).encode("utf-32"))
         return checksum.hexdigest()
     else:
         return uuid1().hex
diff --git a/pytools/persistent_dict.py b/pytools/persistent_dict.py
index 89a2ebf..cad339c 100644
--- a/pytools/persistent_dict.py
+++ b/pytools/persistent_dict.py
@@ -249,7 +249,7 @@ class KeyBuilder(object):
     if sys.version_info >= (3,):
         @staticmethod
         def update_for_str(key_hash, key):
-            key_hash.update(key.encode('utf8'))
+            key_hash.update(key.encode("utf8"))
 
         @staticmethod
         def update_for_bytes(key_hash, key):
@@ -261,7 +261,7 @@ class KeyBuilder(object):
 
         @staticmethod
         def update_for_unicode(key_hash, key):
-            key_hash.update(key.encode('utf8'))
+            key_hash.update(key.encode("utf8"))
 
     def update_for_tuple(self, key_hash, key):
         for obj_i in key:
@@ -274,11 +274,11 @@ class KeyBuilder(object):
     @staticmethod
     def update_for_NoneType(key_hash, key):  # noqa
         del key
-        key_hash.update("<None>".encode('utf8'))
+        key_hash.update("<None>".encode("utf8"))
 
     @staticmethod
     def update_for_dtype(key_hash, key):
-        key_hash.update(key.str.encode('utf8'))
+        key_hash.update(key.str.encode("utf8"))
 
     # }}}
 
diff --git a/setup.cfg b/setup.cfg
index 9ce1073..f2e50e9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -3,6 +3,10 @@ ignore = E126,E127,E128,E123,E226,E241,E242,E265,E402,W503,E731
 max-line-length=85
 exclude=pytools/arithmetic_container.py,pytools/decorator.py
 
+inline-quotes = "
+docstring-quotes = "
+multiline-quotes = """
+
 [wheel]
 universal = 1
 
diff --git a/test/test_graph_tools.py b/test/test_graph_tools.py
index 311f60d..b9c1905 100644
--- a/test/test_graph_tools.py
+++ b/test/test_graph_tools.py
@@ -226,26 +226,26 @@ def test_prioritzed_topological_sort_examples():
 
     from pytools.graph import compute_topological_order
 
-    keys = {'a': 4, 'b': 3, 'c': 2, 'e': 1, 'd': 4}
+    keys = {"a": 4, "b": 3, "c": 2, "e": 1, "d": 4}
     dag = {
-            'a': ['b', 'c'],
-            'b': [],
-            'c': ['d', 'e'],
-            'd': [],
-            'e': []}
+            "a": ["b", "c"],
+            "b": [],
+            "c": ["d", "e"],
+            "d": [],
+            "e": []}
 
     assert compute_topological_order(dag, key=keys.get) == [
-            'a', 'c', 'e', 'b', 'd']
+            "a", "c", "e", "b", "d"]
 
-    keys = {'a': 7, 'b': 2, 'c': 1, 'd': 0}
+    keys = {"a": 7, "b": 2, "c": 1, "d": 0}
     dag = {
-            'd': set('c'),
-            'b': set('a'),
-            'a': set(),
-            'c': set('a'),
+            "d": set("c"),
+            "b": set("a"),
+            "a": set(),
+            "c": set("a"),
             }
 
-    assert compute_topological_order(dag, key=keys.get) == ['d', 'c', 'b', 'a']
+    assert compute_topological_order(dag, key=keys.get) == ["d", "c", "b", "a"]
 
 
 def test_prioritzed_topological_sort():
-- 
GitLab