diff --git a/infrahub_sdk/branch.py b/infrahub_sdk/branch.py index 2403e1ef..2b1905ce 100644 --- a/infrahub_sdk/branch.py +++ b/infrahub_sdk/branch.py @@ -188,9 +188,7 @@ async def all(self) -> dict[str, BranchData]: query = Query(name="GetAllBranch", query=QUERY_ALL_BRANCHES_DATA) data = await self.client.execute_graphql(query=query.render(), tracker="query-branch-all") - branches = {branch["name"]: BranchData(**branch) for branch in data["Branch"]} - - return branches + return {branch["name"]: BranchData(**branch) for branch in data["Branch"]} async def get(self, branch_name: str) -> BranchData: query = Query(name="GetBranch", query=QUERY_ONE_BRANCH_DATA, variables={"branch_name": str}) @@ -230,9 +228,7 @@ def all(self) -> dict[str, BranchData]: query = Query(name="GetAllBranch", query=QUERY_ALL_BRANCHES_DATA) data = self.client.execute_graphql(query=query.render(), tracker="query-branch-all") - branches = {branch["name"]: BranchData(**branch) for branch in data["Branch"]} - - return branches + return {branch["name"]: BranchData(**branch) for branch in data["Branch"]} def get(self, branch_name: str) -> BranchData: query = Query(name="GetBranch", query=QUERY_ONE_BRANCH_DATA, variables={"branch_name": str}) diff --git a/infrahub_sdk/client.py b/infrahub_sdk/client.py index 18af1985..6b27599a 100644 --- a/infrahub_sdk/client.py +++ b/infrahub_sdk/client.py @@ -307,8 +307,7 @@ def _initialize(self) -> None: async def get_version(self) -> str: """Return the Infrahub version.""" response = await self.execute_graphql(query="query { InfrahubInfo { version }}") - version = response.get("InfrahubInfo", {}).get("version", "") - return version + return response.get("InfrahubInfo", {}).get("version", "") async def get_user(self) -> dict: """Return user information""" @@ -1602,8 +1601,7 @@ def _initialize(self) -> None: def get_version(self) -> str: """Return the Infrahub version.""" response = self.execute_graphql(query="query { InfrahubInfo { version }}") - version = response.get("InfrahubInfo", {}).get("version", "") - return version + return response.get("InfrahubInfo", {}).get("version", "") def get_user(self) -> dict: """Return user information""" diff --git a/infrahub_sdk/diff.py b/infrahub_sdk/diff.py index 6b17b147..fad10080 100644 --- a/infrahub_sdk/diff.py +++ b/infrahub_sdk/diff.py @@ -117,7 +117,7 @@ def diff_tree_node_to_node_diff(node_dict: dict[str, Any], branch_name: str) -> ) relationship_diff["peers"] = peer_diffs element_diffs.append(relationship_diff) - node_diff = NodeDiff( + return NodeDiff( branch=branch_name, kind=str(node_dict.get("kind")), id=str(node_dict.get("uuid")), @@ -125,4 +125,3 @@ def diff_tree_node_to_node_diff(node_dict: dict[str, Any], branch_name: str) -> display_label=str(node_dict.get("label")), elements=element_diffs, ) - return node_diff diff --git a/infrahub_sdk/node/node.py b/infrahub_sdk/node/node.py index e6d129c3..72624467 100644 --- a/infrahub_sdk/node/node.py +++ b/infrahub_sdk/node/node.py @@ -579,8 +579,7 @@ async def artifact_fetch(self, name: str) -> str | dict[str, Any]: self._validate_artifact_support(ARTIFACT_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE) artifact = await self._client.get(kind="CoreArtifact", name__value=name, object__ids=[self.id]) - content = await self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value) - return content + return await self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value) async def delete(self, timeout: int | None = None, request_context: RequestContext | None = None) -> None: input_data = {"data": {"id": self.id}} @@ -1208,8 +1207,7 @@ def artifact_generate(self, name: str) -> None: def artifact_fetch(self, name: str) -> str | dict[str, Any]: self._validate_artifact_support(ARTIFACT_FETCH_FEATURE_NOT_SUPPORTED_MESSAGE) artifact = self._client.get(kind="CoreArtifact", name__value=name, object__ids=[self.id]) - content = self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value) - return content + return self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value) def delete(self, timeout: int | None = None, request_context: RequestContext | None = None) -> None: input_data = {"data": {"id": self.id}} diff --git a/infrahub_sdk/playback.py b/infrahub_sdk/playback.py index 0ec72e8c..c00badc5 100644 --- a/infrahub_sdk/playback.py +++ b/infrahub_sdk/playback.py @@ -56,5 +56,4 @@ def _read_request( with Path(f"{self.directory}/{filename}.json").open(encoding="utf-8") as fobj: data = ujson.load(fobj) - response = httpx.Response(status_code=data["status_code"], content=data["response_content"], request=request) - return response + return httpx.Response(status_code=data["status_code"], content=data["response_content"], request=request) diff --git a/infrahub_sdk/repository.py b/infrahub_sdk/repository.py index 9472c4fa..331d15f1 100644 --- a/infrahub_sdk/repository.py +++ b/infrahub_sdk/repository.py @@ -29,5 +29,4 @@ def initialize_repo(self) -> Repo: @property def active_branch(self) -> str | None: - active_branch = porcelain.active_branch(self.root_directory).decode("utf-8") - return active_branch + return porcelain.active_branch(self.root_directory).decode("utf-8") diff --git a/infrahub_sdk/timestamp.py b/infrahub_sdk/timestamp.py index a9a56278..578a149e 100644 --- a/infrahub_sdk/timestamp.py +++ b/infrahub_sdk/timestamp.py @@ -43,8 +43,7 @@ def obj(self) -> ZonedDateTime: @classmethod def _parse_string(cls, value: str) -> ZonedDateTime: try: - zoned_date = ZonedDateTime.parse_common_iso(value) - return zoned_date + return ZonedDateTime.parse_common_iso(value) except ValueError: pass diff --git a/pyproject.toml b/pyproject.toml index cb185950..0e29c57a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -193,7 +193,6 @@ ignore = [ "PLW1641", # Object does not implement `__hash__` method "PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()` "PTH109", # `os.getcwd()` should be replaced by `Path.cwd()` - "RET504", # Unnecessary assignment to `data` before `return` statement "RUF005", # Consider `[*path, str(key)]` instead of concatenation "RUF015", # Prefer `next(iter(input_data["variables"].keys()))` over single element slice "RUF029", # Function is declared `async`, but doesn't `await` or use `async` features. @@ -273,6 +272,7 @@ max-complexity = 17 "ANN201", # ANN201 Missing return type annotation for public function "ANN202", # Missing return type annotation for private function "ANN204", # Missing return type annotation for special method + "RET504", # Unnecessary assignment to `data` before `return` statement ] "tests/unit/sdk/test_client.py" = [