From 7fedbe9d8d70169ee197ae271f7356f3f0ab0997 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 12 Nov 2024 08:34:55 +0100 Subject: [PATCH] ci: enable pyupgrade rules in ruff --- pyproject.toml | 1 + src/syrupy/extensions/amber/__init__.py | 2 +- src/syrupy/extensions/amber/serializer.py | 2 +- src/syrupy/report.py | 5 +++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 56b2dd1e..cb32dac6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,6 +68,7 @@ extend-select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions "I", # isort + "UP", # pyupgrade ] [build-system] diff --git a/src/syrupy/extensions/amber/__init__.py b/src/syrupy/extensions/amber/__init__.py index 76347031..37291162 100644 --- a/src/syrupy/extensions/amber/__init__.py +++ b/src/syrupy/extensions/amber/__init__.py @@ -53,7 +53,7 @@ def _read_snapshot_collection(self, snapshot_location: str) -> "SnapshotCollecti return self.serializer_class.read_file(snapshot_location) @classmethod - @lru_cache() + @lru_cache def __cacheable_read_snapshot( cls, snapshot_location: str, cache_key: str ) -> "SnapshotCollection": diff --git a/src/syrupy/extensions/amber/serializer.py b/src/syrupy/extensions/amber/serializer.py index 742593a4..fe59f94d 100644 --- a/src/syrupy/extensions/amber/serializer.py +++ b/src/syrupy/extensions/amber/serializer.py @@ -139,7 +139,7 @@ def __read_file_with_markers( missing_version = True try: - with open(filepath, "r", encoding=TEXT_ENCODING, newline=None) as f: + with open(filepath, encoding=TEXT_ENCODING, newline=None) as f: for line_no, line in enumerate(f): if line.startswith(cls._marker_prefix): marker_key, *marker_rest = line[marker_offset:].split( diff --git a/src/syrupy/report.py b/src/syrupy/report.py index d13489c8..6154b9b0 100644 --- a/src/syrupy/report.py +++ b/src/syrupy/report.py @@ -359,8 +359,9 @@ def lines(self) -> Iterator[str]: path_to_file = filepath unused_snapshots = ", ".join(map(bold, sorted(snapshots))) - yield warning_style(gettext(base_message)) + " {} ({})".format( - unused_snapshots, path_to_file + yield ( + warning_style(gettext(base_message)) + + f" {unused_snapshots} ({path_to_file})" ) if not self.update_snapshots: message = gettext(