Skip to content

Commit

Permalink
Merge pull request #15406 from draghuram/ruff-RET508
Browse files Browse the repository at this point in the history
Handle ruff error RET508.
  • Loading branch information
pllim committed Oct 3, 2023
2 parents 00e64a9 + e9df6d7 commit fff1973
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 49 deletions.
1 change: 0 additions & 1 deletion .ruff.toml
Expand Up @@ -179,7 +179,6 @@ ignore = [
"RET505", # superfluous-else-return
"RET506", # superfluous-else-raise
"RET507", # superfluous-else-continue
"RET508", # superfluous-else-break

# flake8-raise (RSE)
"RSE102", # unnecessary-paren-on-raise-exception
Expand Down
19 changes: 10 additions & 9 deletions astropy/io/ascii/sextractor.py
Expand Up @@ -53,15 +53,16 @@ def get_cols(self, lines):
if not line.startswith("#"):
dataline = line # save for later to infer the actual number of columns
break # End of header lines
else:
match = re_name_def.search(line)
if match:
colnumber = int(match.group("colnumber"))
colname = match.group("colname")
coldescr = match.group("coldescr")
# If no units are given, colunit = None
colunit = match.group("colunit")
columns[colnumber] = (colname, coldescr, colunit)

match = re_name_def.search(line)
if match:
colnumber = int(match.group("colnumber"))
colname = match.group("colname")
coldescr = match.group("coldescr")
# If no units are given, colunit = None
colunit = match.group("colunit")
columns[colnumber] = (colname, coldescr, colunit)

# Handle skipped column numbers
colnumbers = sorted(columns)
# Handle the case where the last column is array-like by append a pseudo column
Expand Down
3 changes: 2 additions & 1 deletion astropy/io/fits/hdu/image.py
Expand Up @@ -1050,7 +1050,8 @@ def _getdata(self, keys):
if isinstance(key, slice):
ks = range(*key.indices(axis))
break
elif isiterable(key):

if isiterable(key):
# Handle both integer and boolean arrays.
ks = np.arange(axis, dtype=int)[key]
break
Expand Down
65 changes: 32 additions & 33 deletions astropy/io/votable/tree.py
Expand Up @@ -2740,39 +2740,38 @@ def parse(self, iterator, config):

if (not skip_table) and (len(fields) > 0):
for start, tag, data, pos in iterator:
if start:
if tag == "TABLEDATA":
warn_unknown_attrs("TABLEDATA", data.keys(), config, pos)
self.array = self._parse_tabledata(
iterator, colnumbers, fields, config
)
break
elif tag == "BINARY":
warn_unknown_attrs("BINARY", data.keys(), config, pos)
self.array = self._parse_binary(
1, iterator, colnumbers, fields, config, pos
)
break
elif tag == "BINARY2":
if not config["version_1_3_or_later"]:
warn_or_raise(W52, W52, config["version"], config, pos)
self.array = self._parse_binary(
2, iterator, colnumbers, fields, config, pos
)
break
elif tag == "FITS":
warn_unknown_attrs("FITS", data.keys(), config, pos, ["extnum"])
try:
extnum = int(data.get("extnum", 0))
if extnum < 0:
raise ValueError("'extnum' cannot be negative.")
except ValueError:
vo_raise(E17, (), config, pos)
self.array = self._parse_fits(iterator, extnum, config)
break
else:
warn_or_raise(W37, W37, tag, config, pos)
break
if not start:
continue

if tag == "TABLEDATA":
warn_unknown_attrs("TABLEDATA", data.keys(), config, pos)
self.array = self._parse_tabledata(
iterator, colnumbers, fields, config
)
elif tag == "BINARY":
warn_unknown_attrs("BINARY", data.keys(), config, pos)
self.array = self._parse_binary(
1, iterator, colnumbers, fields, config, pos
)
elif tag == "BINARY2":
if not config["version_1_3_or_later"]:
warn_or_raise(W52, W52, config["version"], config, pos)
self.array = self._parse_binary(
2, iterator, colnumbers, fields, config, pos
)
elif tag == "FITS":
warn_unknown_attrs("FITS", data.keys(), config, pos, ["extnum"])
try:
extnum = int(data.get("extnum", 0))
if extnum < 0:
raise ValueError("'extnum' cannot be negative.")
except ValueError:
vo_raise(E17, (), config, pos)
self.array = self._parse_fits(iterator, extnum, config)
else:
warn_or_raise(W37, W37, tag, config, pos)

break

for start, tag, data, pos in iterator:
if not start and tag == "DATA":
Expand Down
3 changes: 2 additions & 1 deletion astropy/table/pprint.py
Expand Up @@ -809,7 +809,8 @@ def _more_tabcol(

if key.lower() == "q":
break
elif key == " " or key == "f":

if key == " " or key == "f":
i0 += delta_lines
elif key == "b":
i0 = i0 - delta_lines
Expand Down
8 changes: 4 additions & 4 deletions astropy/units/core.py
Expand Up @@ -1322,10 +1322,10 @@ def is_final_result(unit):
for len_bases, composed, tunit in results:
if len_bases > min_length:
break
else:
factored = composed * tunit
if is_final_result(factored):
subresults.add(factored)

factored = composed * tunit
if is_final_result(factored):
subresults.add(factored)

if len(subresults):
cached_results[key] = subresults
Expand Down

0 comments on commit fff1973

Please sign in to comment.