Skip to content

Commit f294168

Browse files
authored
Merge pull request astropy#16264 from eerovaher/ruff-034
Update Ruff `pre-commit` hook to v0.3.4
2 parents 27af91e + f9d233f commit f294168

34 files changed

+170
-200
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ repos:
6060
- tomli
6161

6262
- repo: https://github.com/astral-sh/ruff-pre-commit
63-
rev: "v0.3.0"
63+
rev: "v0.3.4"
6464
hooks:
6565
- id: ruff
6666
args: ["--fix", "--show-fixes"]

astropy/coordinates/baseframe.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,8 @@ def _infer_data(self, args, copy, kwargs):
526526

527527
if len(args) > 0:
528528
raise TypeError(
529-
"{}.__init__ had {} remaining unhandled arguments".format(
530-
self.__class__.__name__, len(args)
531-
)
529+
f"{type(self).__name__}.__init__ had {len(args)} remaining "
530+
"unhandled arguments"
532531
)
533532

534533
if representation_data is None and differential_data is not None:

astropy/io/ascii/core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,8 @@ def check_column_names(self, names, strict_names, guessing):
762762
and self.__class__.__name__ != "EcsvHeader"
763763
):
764764
raise ValueError(
765-
"Table format guessing requires at least two columns, got {}".format(
766-
list(self.colnames)
767-
)
765+
"Table format guessing requires at least two columns, "
766+
f"got {list(self.colnames)}"
768767
)
769768

770769
if names is not None and len(names) != len(self.colnames):

astropy/io/ascii/misc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ def sortmore(*args, **kw):
105105
k = lambda x: (globalkey(*x),) + tuple(f(z) for (f, z) in zip(key, x))
106106
else:
107107
raise KeyError(
108-
"kw arg 'key' should be None, callable, or a sequence of callables, not {}".format(
109-
type(key)
110-
)
108+
"kw arg 'key' should be None, callable, or a sequence of callables, "
109+
f"not {type(key)}"
111110
)
112111

113112
res = sorted(zip(*args), key=k)

astropy/io/ascii/tests/test_c_reader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,9 @@ def test_newline_as_delimiter(delimiter, fast_reader):
16891689
eol = "\r"
16901690

16911691
inp0 = ["a | b | c ", " 1 | '2' | 3.00000 "]
1692-
inp1 = "a {0:s} b {0:s}c{1:s} 1 {0:s}'2'{0:s} 3.0".format(delimiter, eol)
1692+
inp1 = (
1693+
f"a {delimiter:s} b {delimiter:s}c{eol:s} 1 {delimiter:s}'2'{delimiter:s} 3.0"
1694+
)
16931695
inp2 = [f"a {delimiter} b{delimiter} c", f"1{delimiter} '2' {delimiter} 3.0"]
16941696

16951697
t0 = ascii.read(inp0, delimiter="|", fast_reader=fast_reader)
@@ -1704,7 +1706,9 @@ def test_newline_as_delimiter(delimiter, fast_reader):
17041706
assert_table_equal(t2, t0)
17051707

17061708
inp0 = 'a {0:s} b {0:s} c{1:s} 1 {0:s}"2"{0:s} 3.0'.format("|", eol)
1707-
inp1 = 'a {0:s} b {0:s} c{1:s} 1 {0:s}"2"{0:s} 3.0'.format(delimiter, eol)
1709+
inp1 = (
1710+
f'a {delimiter:s} b {delimiter:s} c{eol:s} 1 {delimiter:s}"2"{delimiter:s} 3.0'
1711+
)
17081712

17091713
t0 = ascii.read(inp0, delimiter="|", fast_reader=fast_reader)
17101714
t1 = ascii.read(inp1, delimiter=delimiter, fast_reader=fast_reader)

astropy/io/ascii/ui.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ def _get_format_class(format, reader_writer_cls, label):
208208
reader_writer_cls = core.FORMAT_CLASSES[format]
209209
else:
210210
raise ValueError(
211-
"ASCII format {!r} not in allowed list {}".format(
212-
format, sorted(core.FORMAT_CLASSES)
213-
)
211+
f"ASCII format {format!r} not in allowed list "
212+
f"{sorted(core.FORMAT_CLASSES)}"
214213
)
215214
return reader_writer_cls
216215

@@ -1015,8 +1014,10 @@ def write(
10151014

10161015
if diff_format_with_names:
10171016
warnings.warn(
1018-
"The key(s) {} specified in the formats argument do not match a column"
1019-
" name.".format(diff_format_with_names),
1017+
(
1018+
f"The key(s) {diff_format_with_names} specified in the formats "
1019+
"argument do not match a column name."
1020+
),
10201021
AstropyWarning,
10211022
)
10221023

astropy/io/fits/card.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class Card(_Verify):
129129
_rvkc_identifier = r"[a-zA-Z_]\w*"
130130
_rvkc_field = _rvkc_identifier + r"(\.\d+)?"
131131
_rvkc_field_specifier_s = rf"{_rvkc_field}(\.{_rvkc_field})*"
132-
_rvkc_field_specifier_val = r"(?P<keyword>{}): +(?P<val>{})".format(
133-
_rvkc_field_specifier_s, _numr_FSC
132+
_rvkc_field_specifier_val = (
133+
rf"(?P<keyword>{_rvkc_field_specifier_s}): +(?P<val>{_numr_FSC})"
134134
)
135135
_rvkc_keyword_val = rf"\'(?P<rawval>{_rvkc_field_specifier_val})\'"
136136
_rvkc_keyword_val_comm = rf" *{_rvkc_keyword_val} *(/ *(?P<comm>[ -~]*))?$"
@@ -141,9 +141,7 @@ class Card(_Verify):
141141
# string that is being used to index into a card list that contains
142142
# record value keyword cards (ex. 'DP1.AXIS.1')
143143
_rvkc_keyword_name_RE = re.compile(
144-
r"(?P<keyword>{})\.(?P<field_specifier>{})$".format(
145-
_rvkc_identifier, _rvkc_field_specifier_s
146-
)
144+
rf"(?P<keyword>{_rvkc_identifier})\.(?P<field_specifier>{_rvkc_field_specifier_s})$"
147145
)
148146

149147
# regular expression to extract the field specifier and value and comment

astropy/io/fits/column.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,9 @@ def _verify_keywords(
10921092
# is in the range allowed by the column's format
10931093
msg = (
10941094
"Column null option (TNULLn) is invalid for binary "
1095-
"table columns of type {!r} (got {!r}). The invalid "
1096-
"value will be ignored for the purpose of formatting "
1097-
"the data in this column.".format(format, null)
1095+
f"table columns of type {format!r} (got {null!r}). "
1096+
"The invalid value will be ignored for the purpose of "
1097+
"formatting the data in this column."
10981098
)
10991099

11001100
if msg is None:
@@ -1203,12 +1203,10 @@ def _verify_keywords(
12031203
msg = None
12041204
elif reduce(operator.mul, dims_tuple) > format.repeat:
12051205
msg = (
1206-
"The repeat count of the column format {!r} for column {!r} "
1207-
"is fewer than the number of elements per the TDIM "
1208-
"argument {!r}. The invalid TDIMn value will be ignored "
1209-
"for the purpose of formatting this column.".format(
1210-
name, format, dim
1211-
)
1206+
f"The repeat count of the column format {name!r} for column "
1207+
f"{format!r} is fewer than the number of elements per the TDIM "
1208+
f"argument {dim!r}. The invalid TDIMn value will be ignored "
1209+
"for the purpose of formatting this column."
12121210
)
12131211

12141212
if msg is None:
@@ -1221,8 +1219,8 @@ def _verify_keywords(
12211219
if not isinstance(coord_type, str):
12221220
msg = (
12231221
"Coordinate/axis type option (TCTYPn) must be a string "
1224-
"(got {!r}). The invalid keyword will be ignored for the "
1225-
"purpose of formatting this column.".format(coord_type)
1222+
f"(got {coord_type!r}). The invalid keyword will be ignored "
1223+
"for the purpose of formatting this column."
12261224
)
12271225
elif len(coord_type) > 8:
12281226
msg = (
@@ -1242,8 +1240,8 @@ def _verify_keywords(
12421240
if not isinstance(coord_unit, str):
12431241
msg = (
12441242
"Coordinate/axis unit option (TCUNIn) must be a string "
1245-
"(got {!r}). The invalid keyword will be ignored for the "
1246-
"purpose of formatting this column.".format(coord_unit)
1243+
f"(got {coord_unit!r}). The invalid keyword will be ignored "
1244+
"for the purpose of formatting this column."
12471245
)
12481246

12491247
if msg is None:
@@ -1260,11 +1258,9 @@ def _verify_keywords(
12601258
msg = None
12611259
if not isinstance(v, numbers.Real):
12621260
msg = (
1263-
"Column {} option ({}n) must be a real floating type (got"
1264-
" {!r}). The invalid value will be ignored for the purpose of"
1265-
" formatting the data in this column.".format(
1266-
k, ATTRIBUTE_TO_KEYWORD[k], v
1267-
)
1261+
f"Column {k} option ({ATTRIBUTE_TO_KEYWORD[k]}n) must be a "
1262+
f"real floating type (got {v!r}). The invalid value will be "
1263+
"ignored for the purpose of formatting the data in this column."
12681264
)
12691265

12701266
if msg is None:
@@ -1277,8 +1273,8 @@ def _verify_keywords(
12771273
if not isinstance(time_ref_pos, str):
12781274
msg = (
12791275
"Time coordinate reference position option (TRPOSn) must be "
1280-
"a string (got {!r}). The invalid keyword will be ignored for "
1281-
"the purpose of formatting this column.".format(time_ref_pos)
1276+
f"a string (got {time_ref_pos!r}). The invalid keyword will be "
1277+
"ignored for the purpose of formatting this column."
12821278
)
12831279

12841280
if msg is None:

astropy/io/fits/diff.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,8 @@ def _report(self):
11261126
if self.diff_total > self.numdiffs:
11271127
self._writeln(" ...")
11281128
self._writeln(
1129-
" {} different pixels found ({:.2%} different).".format(
1130-
self.diff_total, self.diff_ratio
1131-
)
1129+
f" {self.diff_total} different pixels found "
1130+
f"({self.diff_ratio:.2%} different)."
11321131
)
11331132

11341133

@@ -1214,9 +1213,8 @@ def _report(self):
12141213

12151214
self._writeln(" ...")
12161215
self._writeln(
1217-
" {} different bytes found ({:.2%} different).".format(
1218-
self.diff_total, self.diff_ratio
1219-
)
1216+
f" {self.diff_total} different bytes found "
1217+
f"({self.diff_ratio:.2%} different)."
12201218
)
12211219

12221220

@@ -1544,9 +1542,8 @@ def _report(self):
15441542
self._writeln(" ...")
15451543

15461544
self._writeln(
1547-
" {} different table data element(s) found ({:.2%} different).".format(
1548-
self.diff_total, self.diff_ratio
1549-
)
1545+
f" {self.diff_total} different table data element(s) found "
1546+
f"({self.diff_ratio:.2%} different)."
15501547
)
15511548

15521549

astropy/io/fits/fitsrec.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,9 @@ def _convert_other(self, column, field, recformat):
936936
actual_nitems = field.shape[1]
937937
if nitems > actual_nitems and not isinstance(recformat, _FormatP):
938938
warnings.warn(
939-
"TDIM{} value {:d} does not fit with the size of "
940-
"the array items ({:d}). TDIM{:d} will be ignored.".format(
941-
indx + 1, self._coldefs[indx].dims, actual_nitems, indx + 1
942-
)
939+
f"TDIM{indx + 1} value {self._coldefs[indx].dims:d} does not "
940+
f"fit with the size of the array items ({actual_nitems:d}). "
941+
f"TDIM{indx + 1:d} will be ignored."
943942
)
944943
dim = None
945944

@@ -1218,14 +1217,11 @@ def _scale_back_strings(self, col_idx, input_field, output_field):
12181217
_ascii_encode(input_field, out=output_field)
12191218
except _UnicodeArrayEncodeError as exc:
12201219
raise ValueError(
1221-
"Could not save column '{}': Contains characters that "
1222-
"cannot be encoded as ASCII as required by FITS, starting "
1223-
"at the index {!r} of the column, and the index {} of "
1224-
"the string at that location.".format(
1225-
self._coldefs[col_idx].name,
1226-
exc.index[0] if len(exc.index) == 1 else exc.index,
1227-
exc.start,
1228-
)
1220+
f"Could not save column '{self._coldefs[col_idx].name}': "
1221+
"Contains characters that cannot be encoded as ASCII as required "
1222+
"by FITS, starting at the index "
1223+
f"{exc.index[0] if len(exc.index) == 1 else exc.index!r} of the "
1224+
f"column, and the index {exc.start} of the string at that location."
12291225
)
12301226
else:
12311227
# Otherwise go ahead and do a direct copy into--if both are type
@@ -1293,9 +1289,8 @@ def _scale_back_ascii(self, col_idx, input_field, output_field):
12931289
value = fmt.format(value)
12941290
if len(value) > starts[col_idx + 1] - starts[col_idx]:
12951291
raise ValueError(
1296-
"Value {!r} does not fit into the output's itemsize of {}.".format(
1297-
value, spans[col_idx]
1298-
)
1292+
f"Value {value!r} does not fit into the output's itemsize of "
1293+
f"{spans[col_idx]}."
12991294
)
13001295

13011296
if trailing_decimal and value[0] == " ":

0 commit comments

Comments
 (0)