From 18901cff4f3afbb2f7d714dd4f22cc77a5b0fd8f Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Sat, 18 Sep 2021 19:42:44 -0500 Subject: [PATCH] run pyupgrade for some newer changes --- pytools/__init__.py | 10 +++++----- pytools/batchjob.py | 2 +- pytools/convergence.py | 2 +- pytools/spatial_btree.py | 10 +++++----- setup.py | 3 +-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pytools/__init__.py b/pytools/__init__.py index 4d98418..228ed61 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -375,7 +375,7 @@ class RecordWithoutPickling: def __repr__(self): return "{}({})".format( self.__class__.__name__, - ", ".join("{}={!r}".format(fld, getattr(self, fld)) + ", ".join(f"{fld}={getattr(self, fld)!r}" for fld in self.__class__.fields if hasattr(self, fld))) @@ -1843,14 +1843,14 @@ class CPyUserInterface: print() print("The following variables are recognized:") for v in sorted(self.variables): - print(" {} = {}".format(v, self.variables[v])) + print(f" {v} = {self.variables[v]}") if v in self.doc: print(" %s" % self.doc[v]) print() print("The following constants are supplied:") for c in sorted(self.constants): - print(" {} = {}".format(c, self.constants[c])) + print(f" {c} = {self.constants[c]}") if c in self.doc: print(" %s" % self.doc[c]) @@ -1925,7 +1925,7 @@ def typedump(val, max_seq=5, special_handlers=None): if isinstance(val, dict): return "{%s}" % ( ", ".join( - "{!r}: {}".format(str(k), typedump(v)) + f"{str(k)!r}: {typedump(v)}" for k, v in val.items())) try: @@ -2726,7 +2726,7 @@ def sphere_sample_equidistant(npoints_approx: int, r: float = 1.0): for m in range(M_theta): theta = np.pi * (m + 0.5) / M_theta - M_phi = int(np.ceil((2 * np.pi * np.sin(theta) / d_phi))) # noqa: N806 + M_phi = int(np.ceil(2 * np.pi * np.sin(theta) / d_phi)) # noqa: N806 for n in range(M_phi): phi = 2 * np.pi * n / M_phi points.append([r * np.sin(theta) * np.cos(phi), diff --git a/pytools/batchjob.py b/pytools/batchjob.py index d5ac7ad..d4369bb 100644 --- a/pytools/batchjob.py +++ b/pytools/batchjob.py @@ -146,7 +146,7 @@ class ConstructorPlaceholder: return "{}({})".format(self.classname, ",".join( [str(arg) for arg in self.args] - + ["{}={}".format(kw, repr(val)) + + [f"{kw}={repr(val)}" for kw, val in self.kwargs.items()] ) ) diff --git a/pytools/convergence.py b/pytools/convergence.py index a9e2dd4..46d8b03 100644 --- a/pytools/convergence.py +++ b/pytools/convergence.py @@ -121,7 +121,7 @@ class EOCRecorder: order = result[0, 1] outfile.write("\n") for absc, _err in self.history: - outfile.write("{:f} {:f}\n".format(absc, const * absc**(-order))) + outfile.write(f"{absc:f} {const * absc**(-order):f}\n") # }}} diff --git a/pytools/spatial_btree.py b/pytools/spatial_btree.py index f5249da..91e0f0d 100644 --- a/pytools/spatial_btree.py +++ b/pytools/spatial_btree.py @@ -142,11 +142,11 @@ class SpatialBinaryTreeBucket: yield el def visualize(self, file): - file.write("{:f} {:f}\n".format(self.bottom_left[0], self.bottom_left[1])) - file.write("{:f} {:f}\n".format(self.top_right[0], self.bottom_left[1])) - file.write("{:f} {:f}\n".format(self.top_right[0], self.top_right[1])) - file.write("{:f} {:f}\n".format(self.bottom_left[0], self.top_right[1])) - file.write("{:f} {:f}\n\n".format(self.bottom_left[0], self.bottom_left[1])) + file.write(f"{self.bottom_left[0]:f} {self.bottom_left[1]:f}\n") + file.write(f"{self.top_right[0]:f} {self.bottom_left[1]:f}\n") + file.write(f"{self.top_right[0]:f} {self.top_right[1]:f}\n") + file.write(f"{self.bottom_left[0]:f} {self.top_right[1]:f}\n") + file.write(f"{self.bottom_left[0]:f} {self.bottom_left[1]:f}\n\n") if self.buckets: for i in self.all_buckets: i.visualize(file) diff --git a/setup.py b/setup.py index e77140c..c92ea98 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #! /usr/bin/env python -# -*- coding: utf-8 -*- from setuptools import setup @@ -15,7 +14,7 @@ exec(compile(version_file_contents, "pytools/version.py", "exec"), ver_dic) setup(name="pytools", version=ver_dic["VERSION_TEXT"], description="A collection of tools for Python", - long_description=open("README.rst", "r").read(), + long_description=open("README.rst").read(), classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", -- GitLab