Skip to content

Commit

Permalink
ruff 'unsafe' autofixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcomer committed Nov 14, 2023
1 parent a290f3c commit fc2d56b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
10 changes: 4 additions & 6 deletions cf_units/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ def suppress_errors():
except _ud.UdunitsError as e:
error_msg = ': "%s"' % e.error_msg() if e.errnum else ""
raise OSError(
"[%s] Failed to open UDUNITS-2 XML unit database%s"
% (e.status_msg(), error_msg)
f"[{e.status_msg()}] Failed to open UDUNITS-2 XML unit database{error_msg}"
)


Expand Down Expand Up @@ -930,7 +929,7 @@ def title(self, value):
dt = self.num2date(value)
result = dt.strftime("%Y-%m-%d %H:%M:%S")
else:
result = "%s %s" % (str(value), self)
result = f"{str(value)} {self}"
return result

@property
Expand Down Expand Up @@ -1793,8 +1792,7 @@ def convert(self, value, other, ctype=FLOAT64, inplace=False):
# Strict type check of numpy array.
if result.dtype.type not in (np.float32, np.float64):
raise TypeError(
"Expect a numpy array of '%s' or '%s'"
% np.float32,
"Expect a numpy array of '{}' or '{}'".format(*np.float32),
np.float64,
)
ctype = result.dtype.type
Expand Down Expand Up @@ -1827,7 +1825,7 @@ def convert(self, value, other, ctype=FLOAT64, inplace=False):
return result
else:
raise ValueError(
"Unable to convert from '%r' to '%r'." % (self, other)
f"Unable to convert from '{self!r}' to '{other!r}'."
)

@property
Expand Down
2 changes: 1 addition & 1 deletion cf_units/_udunits2_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _debug_tokens(unit_string):
continue
token_type_idx = token.type
rule = TOKEN_ID_NAMES[token_type_idx]
print("%s: %s" % (token.text, rule))
print(f"{token.text}: {rule}")


def normalize(unit_string):
Expand Down
2 changes: 1 addition & 1 deletion cf_units/_udunits2_parser/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _repr_ctx(self):
kwargs = ", ".join(
f"{key}={value!r}" for key, value in self._attrs.items()
)
return dict(cls_name=self.__class__.__name__, kwargs=kwargs)
return {"cls_name": self.__class__.__name__, "kwargs": kwargs}

def __repr__(self):
return "{cls_name}({kwargs})".format(**self._repr_ctx())
Expand Down
4 changes: 2 additions & 2 deletions cf_units/_udunits2_parser/parser/udunits2Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,8 +2223,8 @@ def timezone_offset(self):
return localctx

def sempred(self, localctx: RuleContext, ruleIndex: int, predIndex: int):
if self._predicates == None:
self._predicates = dict()
if self._predicates is None:
self._predicates = {}
self._predicates[2] = self.product_sempred
pred = self._predicates.get(ruleIndex, None)
if pred is None:
Expand Down
2 changes: 1 addition & 1 deletion cf_units/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_license_headers(self):
)

failed = False
for fname, last_change in sorted(last_change_by_fname.items()):
for fname, _last_change in sorted(last_change_by_fname.items()):
full_fname = os.path.join(REPO_DIR, fname)
if (
full_fname.endswith(".py")
Expand Down
10 changes: 5 additions & 5 deletions cf_units/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __new__(cls, name, bases, namespace):
if "__init__" not in namespace:
# Create a default __init__ method for the class
method_source = (
"def __init__(self, %s):\n "
"self._init_from_tuple((%s,))" % (args, args)
f"def __init__(self, {args}):\n "
f"self._init_from_tuple(({args},))"
)
exec(method_source, namespace)

Expand All @@ -74,12 +74,12 @@ def __new__(cls, name, bases, namespace):
if "_init" not in namespace:
# Create a default _init method for the class
method_source = (
"def _init(self, %s):\n "
"self._init_from_tuple((%s,))" % (args, args)
f"def _init(self, {args}):\n "
f"self._init_from_tuple(({args},))"
)
exec(method_source, namespace)

return super(_MetaOrderedHashable, cls).__new__(
return super().__new__(
cls, name, bases, namespace
)

Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def _set_builtin(name, value):

cmdclass = {"clean_cython": CleanCython, "build_ext": numpy_build_ext}

kwargs = dict(
cmdclass=cmdclass,
ext_modules=[udunits_ext],
package_data=get_package_data(),
)
kwargs = {
"cmdclass": cmdclass,
"ext_modules": [udunits_ext],
"package_data": get_package_data(),
}

setup(**kwargs)

0 comments on commit fc2d56b

Please sign in to comment.