From e4f1978db4e0f81798297c1b53f4ec7632fd3c16 Mon Sep 17 00:00:00 2001 From: Phillip Simonds Date: Tue, 21 Jan 2025 18:25:15 -0800 Subject: [PATCH] Activate ruff RET503 rule. --- backend/infrahub/core/node/__init__.py | 2 ++ backend/infrahub/database/__init__.py | 3 ++- backend/tests/benchmark/conftest.py | 6 ++++-- backend/tests/unit/core/schema_manager/conftest.py | 2 ++ backend/tests/unit/core/test_relationship_query.py | 2 ++ backend/tests/unit/graphql/conftest.py | 2 ++ models/infrastructure_edge.py | 2 +- pyproject.toml | 1 - 8 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/infrahub/core/node/__init__.py b/backend/infrahub/core/node/__init__.py index 677aa51145..39217c337c 100644 --- a/backend/infrahub/core/node/__init__.py +++ b/backend/infrahub/core/node/__init__.py @@ -113,6 +113,8 @@ async def get_path_value(self, db: InfrahubDatabase, path: str) -> str: attr = getattr(node, schema_path.attribute_schema.name) return getattr(attr, schema_path.attribute_property_name) + raise ValueError(f"Unable to retrieve the value of path {path!r} on {self.get_kind()!r}") + def get_labels(self) -> list[str]: """Return the labels for this object, composed of the kind and the list of Generic this object is inheriting from.""" diff --git a/backend/infrahub/database/__init__.py b/backend/infrahub/database/__init__.py index 24192607d7..ec2d6316f3 100644 --- a/backend/infrahub/database/__init__.py +++ b/backend/infrahub/database/__init__.py @@ -282,7 +282,8 @@ async def __aexit__( traceback: Optional[TracebackType], ): if self._mode == InfrahubDatabaseMode.SESSION: - return await self._session.close() + await self._session.close() + return if self._mode == InfrahubDatabaseMode.TRANSACTION: if exc_type is not None: diff --git a/backend/tests/benchmark/conftest.py b/backend/tests/benchmark/conftest.py index d59e87ff79..465c20adbb 100644 --- a/backend/tests/benchmark/conftest.py +++ b/backend/tests/benchmark/conftest.py @@ -26,7 +26,9 @@ def _wrapper(func, *args, **kwargs): @benchmark def _(): return event_loop.run_until_complete(func(*args, **kwargs)) - else: - return benchmark(func, *args, **kwargs) + + return _ + + return benchmark(func, *args, **kwargs) return _wrapper diff --git a/backend/tests/unit/core/schema_manager/conftest.py b/backend/tests/unit/core/schema_manager/conftest.py index 8811991088..fbe9a853ee 100644 --- a/backend/tests/unit/core/schema_manager/conftest.py +++ b/backend/tests/unit/core/schema_manager/conftest.py @@ -9,6 +9,8 @@ def _get_schema_by_kind(full_schema, kind): if schema_kind == kind: return schema_dict + raise ValueError(f"Schema kind '{kind}' not found in the provided schema.") + @pytest.fixture async def animal_person_schema_dict() -> dict: diff --git a/backend/tests/unit/core/test_relationship_query.py b/backend/tests/unit/core/test_relationship_query.py index 007a206394..552ca585bd 100644 --- a/backend/tests/unit/core/test_relationship_query.py +++ b/backend/tests/unit/core/test_relationship_query.py @@ -274,6 +274,8 @@ def get_active_path_and_rel(all_paths, previous_rel: str): if "Relationship" in node.labels and node.get("uuid") != previous_rel: return path, node + raise ValueError("No active path found") + active_path, latest_rel_node = get_active_path_and_rel(all_paths=paths, previous_rel=rel_node.get("uuid")) rel_data = RelationshipPeerData( diff --git a/backend/tests/unit/graphql/conftest.py b/backend/tests/unit/graphql/conftest.py index e38576e140..ded1c3d671 100644 --- a/backend/tests/unit/graphql/conftest.py +++ b/backend/tests/unit/graphql/conftest.py @@ -41,6 +41,8 @@ def default_branch(self) -> Branch: if self._default_branch: return self._default_branch + raise NotImplementedError() + @pytest.fixture(scope="module") def permissions_helper() -> PermissionsHelper: diff --git a/models/infrastructure_edge.py b/models/infrastructure_edge.py index 511a95cb1f..5c6c54acd0 100644 --- a/models/infrastructure_edge.py +++ b/models/infrastructure_edge.py @@ -2102,7 +2102,7 @@ async def run( config.load_config(profile, num_sites, num_device_per_site, bool_has_bgp_mesh, bool_has_branch) except ConfigError as ex: log.fatal(ex) - return False # FIXME: What should I return here for the script to fail properly + raise # Print config log.info(f"Loading data with {config}") diff --git a/pyproject.toml b/pyproject.toml index dbad96b929..e460a90979 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -437,7 +437,6 @@ ignore = [ "PLR6301", # Method could be a function, class method, or static method "PLW0603", # Using the global statement to update `SETTINGS` is discouraged "PLW1508", # Invalid type for environment variable default; expected `str` or `None` - "RET503", # Missing explicit `return` at the end of function able to return non-`None` value "RET504", # Unnecessary assignment before `return` statement "RUF005", # Consider `[*list(peers.values()), rfc5735]` instead of concatenation "RUF006", # Store a reference to the return value of `asyncio.create_task`