Skip to content

Commit a406bb0

Browse files
authored
Merge pull request #542 from opsmill/pog-returns
Remove unnecessary assignments before `return` statement
2 parents 565674f + 8c266e7 commit a406bb0

File tree

8 files changed

+11
-23
lines changed

8 files changed

+11
-23
lines changed

infrahub_sdk/branch.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ async def all(self) -> dict[str, BranchData]:
188188
query = Query(name="GetAllBranch", query=QUERY_ALL_BRANCHES_DATA)
189189
data = await self.client.execute_graphql(query=query.render(), tracker="query-branch-all")
190190

191-
branches = {branch["name"]: BranchData(**branch) for branch in data["Branch"]}
192-
193-
return branches
191+
return {branch["name"]: BranchData(**branch) for branch in data["Branch"]}
194192

195193
async def get(self, branch_name: str) -> BranchData:
196194
query = Query(name="GetBranch", query=QUERY_ONE_BRANCH_DATA, variables={"branch_name": str})
@@ -230,9 +228,7 @@ def all(self) -> dict[str, BranchData]:
230228
query = Query(name="GetAllBranch", query=QUERY_ALL_BRANCHES_DATA)
231229
data = self.client.execute_graphql(query=query.render(), tracker="query-branch-all")
232230

233-
branches = {branch["name"]: BranchData(**branch) for branch in data["Branch"]}
234-
235-
return branches
231+
return {branch["name"]: BranchData(**branch) for branch in data["Branch"]}
236232

237233
def get(self, branch_name: str) -> BranchData:
238234
query = Query(name="GetBranch", query=QUERY_ONE_BRANCH_DATA, variables={"branch_name": str})

infrahub_sdk/client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ def _initialize(self) -> None:
307307
async def get_version(self) -> str:
308308
"""Return the Infrahub version."""
309309
response = await self.execute_graphql(query="query { InfrahubInfo { version }}")
310-
version = response.get("InfrahubInfo", {}).get("version", "")
311-
return version
310+
return response.get("InfrahubInfo", {}).get("version", "")
312311

313312
async def get_user(self) -> dict:
314313
"""Return user information"""
@@ -1602,8 +1601,7 @@ def _initialize(self) -> None:
16021601
def get_version(self) -> str:
16031602
"""Return the Infrahub version."""
16041603
response = self.execute_graphql(query="query { InfrahubInfo { version }}")
1605-
version = response.get("InfrahubInfo", {}).get("version", "")
1606-
return version
1604+
return response.get("InfrahubInfo", {}).get("version", "")
16071605

16081606
def get_user(self) -> dict:
16091607
"""Return user information"""

infrahub_sdk/diff.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ def diff_tree_node_to_node_diff(node_dict: dict[str, Any], branch_name: str) ->
117117
)
118118
relationship_diff["peers"] = peer_diffs
119119
element_diffs.append(relationship_diff)
120-
node_diff = NodeDiff(
120+
return NodeDiff(
121121
branch=branch_name,
122122
kind=str(node_dict.get("kind")),
123123
id=str(node_dict.get("uuid")),
124124
action=str(node_dict.get("status")),
125125
display_label=str(node_dict.get("label")),
126126
elements=element_diffs,
127127
)
128-
return node_diff

infrahub_sdk/node/node.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ async def artifact_fetch(self, name: str) -> str | dict[str, Any]:
579579
self._validate_artifact_support(ARTIFACT_GENERATE_FEATURE_NOT_SUPPORTED_MESSAGE)
580580

581581
artifact = await self._client.get(kind="CoreArtifact", name__value=name, object__ids=[self.id])
582-
content = await self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value)
583-
return content
582+
return await self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value)
584583

585584
async def delete(self, timeout: int | None = None, request_context: RequestContext | None = None) -> None:
586585
input_data = {"data": {"id": self.id}}
@@ -1208,8 +1207,7 @@ def artifact_generate(self, name: str) -> None:
12081207
def artifact_fetch(self, name: str) -> str | dict[str, Any]:
12091208
self._validate_artifact_support(ARTIFACT_FETCH_FEATURE_NOT_SUPPORTED_MESSAGE)
12101209
artifact = self._client.get(kind="CoreArtifact", name__value=name, object__ids=[self.id])
1211-
content = self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value)
1212-
return content
1210+
return self._client.object_store.get(identifier=artifact._get_attribute(name="storage_id").value)
12131211

12141212
def delete(self, timeout: int | None = None, request_context: RequestContext | None = None) -> None:
12151213
input_data = {"data": {"id": self.id}}

infrahub_sdk/playback.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ def _read_request(
5656
with Path(f"{self.directory}/{filename}.json").open(encoding="utf-8") as fobj:
5757
data = ujson.load(fobj)
5858

59-
response = httpx.Response(status_code=data["status_code"], content=data["response_content"], request=request)
60-
return response
59+
return httpx.Response(status_code=data["status_code"], content=data["response_content"], request=request)

infrahub_sdk/repository.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ def initialize_repo(self) -> Repo:
2929

3030
@property
3131
def active_branch(self) -> str | None:
32-
active_branch = porcelain.active_branch(self.root_directory).decode("utf-8")
33-
return active_branch
32+
return porcelain.active_branch(self.root_directory).decode("utf-8")

infrahub_sdk/timestamp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def obj(self) -> ZonedDateTime:
4343
@classmethod
4444
def _parse_string(cls, value: str) -> ZonedDateTime:
4545
try:
46-
zoned_date = ZonedDateTime.parse_common_iso(value)
47-
return zoned_date
46+
return ZonedDateTime.parse_common_iso(value)
4847
except ValueError:
4948
pass
5049

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ ignore = [
193193
"PLW1641", # Object does not implement `__hash__` method
194194
"PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()`
195195
"PTH109", # `os.getcwd()` should be replaced by `Path.cwd()`
196-
"RET504", # Unnecessary assignment to `data` before `return` statement
197196
"RUF005", # Consider `[*path, str(key)]` instead of concatenation
198197
"RUF015", # Prefer `next(iter(input_data["variables"].keys()))` over single element slice
199198
"RUF029", # Function is declared `async`, but doesn't `await` or use `async` features.
@@ -273,6 +272,7 @@ max-complexity = 17
273272
"ANN201", # ANN201 Missing return type annotation for public function
274273
"ANN202", # Missing return type annotation for private function
275274
"ANN204", # Missing return type annotation for special method
275+
"RET504", # Unnecessary assignment to `data` before `return` statement
276276
]
277277

278278
"tests/unit/sdk/test_client.py" = [

0 commit comments

Comments
 (0)