Skip to content

Commit

Permalink
Ruff update [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Aug 9, 2023
1 parent 63d027f commit 89e36c0
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.282"
rev: "v0.0.283"
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion examples/time_series/power_spectra_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
fig, ax = plt.subplots()
ax.semilogy(freq, spectra)
ax.set_title(f'Power Spectrum of {x_ray}')
ax.set_ylabel('Power Spectral Density [{:LaTeX}]'.format(ts.units[x_ray] ** 2 / u.Hz))
ax.set_ylabel(f'Power Spectral Density [{ts.units[x_ray] ** 2 / u.Hz:LaTeX}]')
ax.set_xlabel('Frequency [Hz]')
plt.show()
4 changes: 2 additions & 2 deletions sunpy/database/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def __init__(self, database_entry):

def __str__(self):
return (
'the database entry {!r} cannot be removed because it '
'is not stored in the database'.format(self.database_entry))
f'the database entry {self.database_entry!r} cannot be removed because it '
'is not stored in the database')


class NonRemovableTagError(Exception):
Expand Down
12 changes: 6 additions & 6 deletions sunpy/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def __init__(self, database_entry):

def __str__(self):
return (
'the entry {!r} was already added '
'to the database'.format(self.database_entry))
f'the entry {self.database_entry!r} was already added '
'to the database')


class EntryAlreadyStarredError(Exception):
Expand All @@ -72,8 +72,8 @@ def __init__(self, database_entry):

def __str__(self):
return (
'the entry {!r} is already marked '
'as starred'.format(self.database_entry))
f'the entry {self.database_entry!r} is already marked '
'as starred')


class EntryAlreadyUnstarredError(Exception):
Expand All @@ -87,8 +87,8 @@ def __init__(self, database_entry):

def __str__(self):
return (
'the entry {!r} is already not marked '
'as starred'.format(self.database_entry))
f'the entry {self.database_entry!r} is already not marked '
'as starred')


class NoSuchTagError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions sunpy/database/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def __init__(self, waveunit):

def __str__(self):
return (
'the waveunit {!r} cannot be converted to an '
'astropy.units.Unit instance'.format(self.waveunit))
f'the waveunit {self.waveunit!r} cannot be converted to an '
'astropy.units.Unit instance')


class JSONDump(Base):
Expand Down
2 changes: 1 addition & 1 deletion sunpy/io/_jp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def header_to_xml(header):

el = ET.SubElement(fits, key)
data = header.get(key)
if type(data) == bool:
if isinstance(data, bool):
data = "1" if data else "0"
else:
data = str(data)
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/dataretriever/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def _get_match_dict(cls, *args, **kwargs):
matchdict['Wavelength'] = elem
else:
raise ValueError(
"GenericClient can not add {} to the rowdict dictionary to"
"pass to the Client.".format(elem.__class__.__name__))
f"GenericClient can not add {elem.__class__.__name__} to the rowdict dictionary to"
"pass to the Client.")
return matchdict

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, pattern, regex=False, **kwargs):
warn_user('regexp being used, the extra arguments passed are being ignored')
else:
self.pattern = pattern.format(**kwargs)
self.domain = "{0.scheme}://{0.netloc}/".format(urlsplit(self.pattern))
self.domain = f"{urlsplit(self.pattern).scheme}://{urlsplit(self.pattern).netloc}/"
milliseconds = re.search(r'\%e', self.pattern)
if not milliseconds:
self.now = datetime.now().strftime(self.pattern)
Expand Down Expand Up @@ -343,7 +343,7 @@ def _ftpfileslist(self, timerange):
if self._check_timerange(fullpath, timerange):
filesurls.append(fullpath)

filesurls = ['ftp://' + "{0.netloc}{0.path}".format(urlsplit(url))
filesurls = ['ftp://' + f"{urlsplit(url).netloc}{urlsplit(url).path}"
for url in filesurls]

return filesurls
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/tests/test_helioviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def client():
client.sources = client.get_data_sources()
return client
except urllib.error.HTTPError as e:
pytest.skip("There was a HTTP error {} {} for "
"HelioViewer.".format(e.code, e.args))
pytest.skip(f"There was a HTTP error {e.code} {e.args} for "
"HelioViewer.")


@pytest.mark.remote_data
Expand Down
22 changes: 8 additions & 14 deletions sunpy/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ def __init__(self, *args, **kwargs):

for candidate in kwargs.keys():
if candidate in self.prohibited_attrs:
raise ValueError("kwarg '{kwarg}' is already an attribute "
"of {datastore} or {obj}".format(kwarg=candidate,
datastore=type(self._datastore),
obj=type(self)))
raise ValueError(f"kwarg '{candidate}' is already an attribute "
f"of {type(self._datastore)} or {type(self)}")
self.update(dict(*args, **kwargs))

def __getattr__(self, name):
Expand All @@ -68,15 +66,13 @@ def __getitem__(self, name):

def __setitem__(self, name, value):
if name in self.prohibited_attrs:
raise ValueError("Name '{name}' is already an attribute "
"of {datastore} or {obj}".format(name=name,
datastore=type(self._datastore),
obj=type(self)))
raise ValueError(f"Name '{name}' is already an attribute "
f"of {type(self._datastore)} or {type(self)}")
self._datastore[name] = value

def __delitem__(self, name):
raise NotImplementedError("'del' operation for {} "
"not supported".format(self.__class__.__name__))
raise NotImplementedError(f"'del' operation for {self.__class__.__name__} "
"not supported")

def __iter__(self):
return iter(self._datastore)
Expand Down Expand Up @@ -217,7 +213,5 @@ def close(self):
self.data = ''

def __repr__(self):
return ("<{module}.{name} file '{file}' mode '{mode}' "
"at {address}>".format(module=self.__module__, name=self.__class__.__name__,
file=self.file, mode=self.mode,
address=hex(id(self))))
return (f"<{self.__module__}.{self.__class__.__name__} file '{self.file}' mode '{self.mode}' "
f"at {hex(id(self))}>")
2 changes: 1 addition & 1 deletion sunpy/tests/tests/test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_read_only_mode_MockOpenTextFile():
Reading from a read only file, writing should be prohibited.
"""
new_line = '\n'
content = r'a{0}bc{0}nd{0}{0}'.format(new_line)
content = fr'a{new_line}bc{new_line}nd{new_line}{new_line}'

read_only = MockOpenTextFile('rom.txt', data=content)
assert read_only.readable() is True
Expand Down
4 changes: 2 additions & 2 deletions sunpy/timeseries/timeseries_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ def _get_matching_widget(self, **kwargs):
else:
candidate_widget_types = [self.default_widget_type]
elif n_matches > 1:
raise MultipleMatchError("Too many candidate types identified ({})."
raise MultipleMatchError(f"Too many candidate types identified ({n_matches})."
"Specify enough keywords to guarantee unique type "
"identification.".format(n_matches))
"identification.")

# Only one suitable source class is found
return candidate_widget_types[0]
Expand Down
4 changes: 2 additions & 2 deletions sunpy/util/datatype_factory_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def _check_registered_widget(self, *args, **kwargs):
else:
candidate_widget_types = [self.default_widget_type]
elif n_matches > 1:
raise MultipleMatchError("Too many candidate types identified ({})."
raise MultipleMatchError(f"Too many candidate types identified ({n_matches})."
"Specify enough keywords to guarantee unique type "
"identification.".format(n_matches))
"identification.")

# Only one is found
WidgetType = candidate_widget_types[0]
Expand Down
6 changes: 2 additions & 4 deletions tools/unify_section_headings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def replace_header_chars(filename):
if new_level > level + 1:
# doc tries to jump up too many levels
raise ValueError(
"ERROR misorder new_level={} level={} "
"char={} header_chars={} on line {}".format(
new_level, level, char, header_chars, i
)
f"ERROR misorder new_level={new_level} level={level} "
f"char={char} header_chars={header_chars} on line {i}"
)
else:
level = new_level
Expand Down

0 comments on commit 89e36c0

Please sign in to comment.