Skip to content

Commit

Permalink
chore: upgrade ruff to v0.7.0 (#1437)
Browse files Browse the repository at this point in the history
Currently, we are using ruff 0.4.5 but recently 0.7.0 was released, this
PR upgrades ruff to 0.7.0 for both formatting and linting.

Closes #1335.
  • Loading branch information
IronCore864 authored Oct 23, 2024
1 parent a52082e commit 457ca76
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ops/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def register_type(
parent_path = parent.path

kind_: str = kind or cls.handle_kind
self._type_registry[(parent_path, kind_)] = cls
self._type_registry[parent_path, kind_] = cls
self._type_known.add(cls)

def save_snapshot(self, value: Union['StoredStateData', 'EventBase']):
Expand Down
2 changes: 1 addition & 1 deletion ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3216,7 +3216,7 @@ def feed(self, data: bytes):
self._parser.feed(data)

def _prepare_tempfile(self, filename: str):
tf = tempfile.NamedTemporaryFile(delete=False)
tf = tempfile.NamedTemporaryFile(delete=False) # noqa: SIM115
self._files[filename] = tf # type: ignore # we have a custom protocol for it
self.current_filename = filename

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ ignore = [
"RUF015",
# Mutable class attributes should be annotated with `typing.ClassVar`
"RUF012",
# Unnecessary dict comprehension for iterable; use `dict.fromkeys` instead
"RUF025",
# Unnecessary `tuple` call (rewrite as a literal)
"C408",
# Unnecessary dict comprehension for iterable; use `dict.fromkeys` instead
"C420",
]

[tool.ruff.lint.pyupgrade]
Expand Down
4 changes: 2 additions & 2 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ def test_hook_and_dispatch_with_failing_hook(
request: pytest.FixtureRequest,
fake_script: FakeScript,
):
self.stdout = self.stderr = tempfile.TemporaryFile()
self.stdout = self.stderr = tempfile.TemporaryFile() # noqa: SIM115
request.addfinalizer(self.stdout.close)

fake_script_hooks = FakeScript(request, self.hooks_dir)
Expand Down Expand Up @@ -1383,7 +1383,7 @@ def _call_event(
@pytest.mark.usefixtures('setup_charm')
def test_crash_action(self, request: pytest.FixtureRequest, fake_script: FakeScript):
self._prepare_actions()
self.stderr = tempfile.TemporaryFile('w+t')
self.stderr = tempfile.TemporaryFile('w+t') # noqa: SIM115
request.addfinalizer(self.stderr.close)
fake_script.write('action-get', "echo '{}'")
with pytest.raises(subprocess.CalledProcessError):
Expand Down
2 changes: 1 addition & 1 deletion test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ def test_relation_set_juju_version_quirks(
version: str,
):
# on 2.7.0+, things proceed as expected
t = tempfile.NamedTemporaryFile()
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'relation-set',
Expand Down
6 changes: 3 additions & 3 deletions test/test_pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3691,9 +3691,9 @@ def test_wait_passed_output_bad_command(
assert io_ws.sends == []

def test_wait_file_io(self, client: MockClient):
fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
out = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
err = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
out = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
err = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
try:
fin.write('foo\n')
fin.seek(0)
Expand Down
4 changes: 2 additions & 2 deletions test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def test_is_available(self, fake_script: FakeScript):
assert fake_script.calls(clear=True) == []

def test_set_encodes_args(self, fake_script: FakeScript):
t = tempfile.NamedTemporaryFile()
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'state-set',
Expand Down Expand Up @@ -478,7 +478,7 @@ def test_get(self, fake_script: FakeScript):
]

def test_set_and_get_complex_value(self, fake_script: FakeScript):
t = tempfile.NamedTemporaryFile()
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'state-set',
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ commands =
[testenv:fmt]
description = Apply coding style standards to code
deps =
ruff==0.4.5
ruff==0.7.0
commands =
ruff format --preview

[testenv:lint]
description = Check code against coding style standards
deps =
ruff==0.4.5
ruff==0.7.0
codespell==2.3.0
commands =
ruff check --preview
Expand Down

0 comments on commit 457ca76

Please sign in to comment.