Skip to content

Commit 1dcbcec

Browse files
authored
Merge pull request #642 from opsmill/pog-PLR6201-infrahub-develop-20251118
Use a `set` literal when testing for membership
2 parents a2d9569 + 8d6a51c commit 1dcbcec

File tree

12 files changed

+23
-24
lines changed

12 files changed

+23
-24
lines changed

infrahub_sdk/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def _build_ip_prefix_allocation_query(
299299
if prefix_length:
300300
input_data["prefix_length"] = prefix_length
301301
if member_type:
302-
if member_type not in ("prefix", "address"):
302+
if member_type not in {"prefix", "address"}:
303303
raise ValueError("member_type possible values are 'prefix' or 'address'")
304304
input_data["member_type"] = member_type
305305
if prefix_type:
@@ -956,7 +956,7 @@ async def execute_graphql(
956956
try:
957957
resp = await self._post(url=url, payload=payload, headers=headers, timeout=timeout)
958958

959-
if raise_for_error in (None, True):
959+
if raise_for_error in {None, True}:
960960
resp.raise_for_status()
961961

962962
retry = False
@@ -970,7 +970,7 @@ async def execute_graphql(
970970
self.log.error(f"Unable to connect to {self.address} .. ")
971971
raise
972972
except httpx.HTTPStatusError as exc:
973-
if exc.response.status_code in [401, 403]:
973+
if exc.response.status_code in {401, 403}:
974974
response = decode_json(response=exc.response)
975975
errors = response.get("errors", [])
976976
messages = [error.get("message") for error in errors]
@@ -1208,7 +1208,7 @@ async def query_gql_query(
12081208
timeout=timeout or self.default_timeout,
12091209
)
12101210

1211-
if raise_for_error in (None, True):
1211+
if raise_for_error in {None, True}:
12121212
resp.raise_for_status()
12131213

12141214
return decode_json(response=resp)
@@ -1817,7 +1817,7 @@ def execute_graphql(
18171817
try:
18181818
resp = self._post(url=url, payload=payload, headers=headers, timeout=timeout)
18191819

1820-
if raise_for_error in (None, True):
1820+
if raise_for_error in {None, True}:
18211821
resp.raise_for_status()
18221822

18231823
retry = False
@@ -1831,7 +1831,7 @@ def execute_graphql(
18311831
self.log.error(f"Unable to connect to {self.address} .. ")
18321832
raise
18331833
except httpx.HTTPStatusError as exc:
1834-
if exc.response.status_code in [401, 403]:
1834+
if exc.response.status_code in {401, 403}:
18351835
response = decode_json(response=exc.response)
18361836
errors = response.get("errors", [])
18371837
messages = [error.get("message") for error in errors]
@@ -2446,7 +2446,7 @@ def query_gql_query(
24462446
timeout=timeout or self.default_timeout,
24472447
)
24482448

2449-
if raise_for_error in (None, True):
2449+
if raise_for_error in {None, True}:
24502450
resp.raise_for_status()
24512451

24522452
return decode_json(response=resp)

infrahub_sdk/node/node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ async def generate_query_data_node(
741741

742742
if (
743743
rel_schema.cardinality == RelationshipCardinality.MANY # type: ignore[union-attr]
744-
and rel_schema.kind not in [RelationshipKind.ATTRIBUTE, RelationshipKind.PARENT] # type: ignore[union-attr]
744+
and rel_schema.kind not in {RelationshipKind.ATTRIBUTE, RelationshipKind.PARENT} # type: ignore[union-attr]
745745
and not (include and rel_name in include)
746746
):
747747
continue
@@ -1386,7 +1386,7 @@ def generate_query_data_node(
13861386

13871387
if (
13881388
rel_schema.cardinality == RelationshipCardinality.MANY # type: ignore[union-attr]
1389-
and rel_schema.kind not in [RelationshipKind.ATTRIBUTE, RelationshipKind.PARENT] # type: ignore[union-attr]
1389+
and rel_schema.kind not in {RelationshipKind.ATTRIBUTE, RelationshipKind.PARENT} # type: ignore[union-attr]
13901390
and not (include and rel_name in include)
13911391
):
13921392
continue

infrahub_sdk/object_store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def get(self, identifier: str, tracker: str | None = None) -> str:
3333
self.client.log.error(f"Unable to connect to {self.client.address} .. ")
3434
raise
3535
except httpx.HTTPStatusError as exc:
36-
if exc.response.status_code in [401, 403]:
36+
if exc.response.status_code in {401, 403}:
3737
response = exc.response.json()
3838
errors = response.get("errors")
3939
messages = [error.get("message") for error in errors]
@@ -54,7 +54,7 @@ async def upload(self, content: str, tracker: str | None = None) -> dict[str, st
5454
self.client.log.error(f"Unable to connect to {self.client.address} .. ")
5555
raise
5656
except httpx.HTTPStatusError as exc:
57-
if exc.response.status_code in [401, 403]:
57+
if exc.response.status_code in {401, 403}:
5858
response = exc.response.json()
5959
errors = response.get("errors")
6060
messages = [error.get("message") for error in errors]
@@ -81,7 +81,7 @@ def get(self, identifier: str, tracker: str | None = None) -> str:
8181
self.client.log.error(f"Unable to connect to {self.client.address} .. ")
8282
raise
8383
except httpx.HTTPStatusError as exc:
84-
if exc.response.status_code in [401, 403]:
84+
if exc.response.status_code in {401, 403}:
8585
response = exc.response.json()
8686
errors = response.get("errors")
8787
messages = [error.get("message") for error in errors]
@@ -102,7 +102,7 @@ def upload(self, content: str, tracker: str | None = None) -> dict[str, str]:
102102
self.client.log.error(f"Unable to connect to {self.client.address} .. ")
103103
raise
104104
except httpx.HTTPStatusError as exc:
105-
if exc.response.status_code in [401, 403]:
105+
if exc.response.status_code in {401, 403}:
106106
response = exc.response.json()
107107
errors = response.get("errors")
108108
messages = [error.get("message") for error in errors]

infrahub_sdk/protocols_generator/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, schema: dict[str, MainSchemaTypesAll]) -> None:
5656
if not e.startswith("__")
5757
and not e.endswith("__")
5858
and e
59-
not in ("TYPE_CHECKING", "CoreNode", "Optional", "Protocol", "Union", "annotations", "runtime_checkable")
59+
not in {"TYPE_CHECKING", "CoreNode", "Optional", "Protocol", "Union", "annotations", "runtime_checkable"}
6060
]
6161

6262
self.sorted_generics = self._sort_and_filter_models(self.generics, filters=["CoreNode"] + self.base_protocols)

infrahub_sdk/pytest_plugin/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def parse_user_provided_data(path: Path | None) -> Any:
5555

5656
if suffix and suffix == "json":
5757
return ujson.loads(text)
58-
if suffix in ("yml", "yaml"):
58+
if suffix in {"yml", "yaml"}:
5959
return yaml.safe_load(text)
6060

6161
return text

infrahub_sdk/pytest_plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def pytest_sessionstart(session: Session) -> None:
9090

9191

9292
def pytest_collect_file(parent: Collector | Item, file_path: Path) -> InfrahubYamlFile | None:
93-
if file_path.suffix in [".yml", ".yaml"] and file_path.name.startswith("test_"):
93+
if file_path.suffix in {".yml", ".yaml"} and file_path.name.startswith("test_"):
9494
return InfrahubYamlFile.from_parent(parent, path=file_path)
9595
return None
9696

infrahub_sdk/schema/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ def _validate_load_schema_response(response: httpx.Response) -> SchemaLoadRespon
193193
hash=status["hash"], previous_hash=status["previous_hash"], warnings=status.get("warnings") or []
194194
)
195195

196-
if response.status_code in [
196+
if response.status_code in {
197197
httpx.codes.BAD_REQUEST,
198198
httpx.codes.UNPROCESSABLE_ENTITY,
199199
httpx.codes.UNAUTHORIZED,
200200
httpx.codes.FORBIDDEN,
201-
]:
201+
}:
202202
return SchemaLoadResponse(errors=response.json())
203203

204204
response.raise_for_status()

infrahub_sdk/spec/object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def is_valid(self) -> bool:
7474

7575
@property
7676
def is_reference(self) -> bool:
77-
return self.format in [RelationshipDataFormat.ONE_REF, RelationshipDataFormat.MANY_REF]
77+
return self.format in {RelationshipDataFormat.ONE_REF, RelationshipDataFormat.MANY_REF}
7878

7979
def get_context(self, value: Any) -> dict:
8080
"""Return a dict to insert to the context if the relationship is mandatory"""

infrahub_sdk/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def str_to_bool(value: str) -> bool:
168168
if isinstance(value, bool):
169169
return value
170170

171-
if isinstance(value, int) and value in [0, 1]:
171+
if isinstance(value, int) and value in {0, 1}:
172172
return bool(value)
173173

174174
if not isinstance(value, str):

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ ignore = [
196196
"PLR0913", # Too many arguments in function definition
197197
"PLR0917", # Too many positional arguments
198198
"PLR2004", # Magic value used in comparison
199-
"PLR6201", # Use a `set` literal when testing for membership
200199
"PLR6301", # Method could be a function, class method, or static method
201200
"PLW0603", # Using the global statement to update `SETTINGS` is discouraged
202201
"PLW1641", # Object does not implement `__hash__` method

0 commit comments

Comments
 (0)