Skip to content

Commit e934f82

Browse files
committed
chore: Pass code style
1 parent cc17651 commit e934f82

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

scim2_models/base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class _SCIMClassInfo(NamedTuple):
116116
complex_fields: frozenset[str] = frozenset()
117117
"""Field names whose root type is a ``ComplexAttribute`` subclass."""
118118

119-
extensions: frozenset[set] = frozenset()
119+
extensions: frozenset[str] = frozenset()
120120
"""Field names whose root type is a ``Extension`` subclass."""
121121

122122

@@ -288,7 +288,7 @@ def __pydantic_on_complete__(cls) -> None:
288288

289289
# Is extension
290290
if (
291-
main_schema
291+
extension_cls is not None
292292
and isclass(root_type)
293293
and issubclass(root_type, extension_cls)
294294
):
@@ -465,7 +465,6 @@ def _apply_replace_constraints(self, original: Self) -> None:
465465
466466
Recursively applies to nested single-valued complex attributes.
467467
"""
468-
469468
for field_name in type(self).model_fields:
470469
mutability = type(self).get_field_annotation(field_name, Mutability)
471470
original_val = getattr(original, field_name)
@@ -485,15 +484,16 @@ def _apply_replace_constraints(self, original: Self) -> None:
485484
attribute=field_name, mutability="immutable"
486485
)
487486

488-
complex_and_extensions = self.__scim_info__.complex_fields.union(self.__scim_info__.extensions)
487+
complex_and_extensions = self.__scim_info__.complex_fields.union(
488+
self.__scim_info__.extensions
489+
)
489490
for complex_attr in complex_and_extensions:
490491
if not type(self).get_field_multiplicity(complex_attr):
491492
original_sub = getattr(original, complex_attr)
492493
replacement_sub = getattr(self, complex_attr)
493494
if original_sub is not None and replacement_sub is not None:
494495
replacement_sub._apply_replace_constraints(original_sub)
495496

496-
497497
def get_attribute_urn(self, field_name: str) -> str:
498498
"""Build the full URN of the attribute.
499499
@@ -542,7 +542,11 @@ def scim_serializer(
542542

543543
# Delete empty extensions
544544
for extension_field in self.__scim_info__.extensions:
545-
key = self.__scim_info__.attribute_urns[extension_field] if info.by_alias else extension_field
545+
key = (
546+
self.__scim_info__.attribute_urns[extension_field]
547+
if info.by_alias
548+
else extension_field
549+
)
546550
if key in serialized and serialized[key] is None:
547551
del serialized[key]
548552

scim2_models/resources/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def from_schema(cls, schema: "Schema") -> type["Extension"]:
112112

113113
def _extension_serializer(
114114
value: Any, handler: SerializerFunctionWrapHandler, info: SerializationInfo
115-
) -> dict[str, Any] | None:
115+
) -> Any:
116116
"""Exclude the Resource attributes from the extension dump.
117117
118118
For instance, attributes 'meta', 'id' or 'schemas' should not be

tests/test_model_serialization.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from scim2_models.annotations import Returned
88
from scim2_models.attributes import ComplexAttribute
99
from scim2_models.context import Context
10-
from scim2_models.resources.resource import Resource
1110
from scim2_models.resources.resource import Extension
11+
from scim2_models.resources.resource import Resource
1212

1313

1414
class SubRetModel(ComplexAttribute):
@@ -155,7 +155,7 @@ def test_dump_default(mut_resource):
155155

156156

157157
def test_dump_extension(mut_resource_extension):
158-
"""Test dumps with extension"""
158+
"""Test dumps with extension."""
159159
assert mut_resource_extension.model_dump() == {
160160
"schemas": ["urn:org:example:MutResource", "urn:org:extensions:MutExtension"],
161161
"id": "id",
@@ -168,7 +168,7 @@ def test_dump_extension(mut_resource_extension):
168168
"readWrite": "y",
169169
"immutable": "y",
170170
"writeOnly": "y",
171-
}
171+
},
172172
}
173173

174174
assert mut_resource_extension.model_dump(scim_ctx=None) == {
@@ -186,7 +186,7 @@ def test_dump_extension(mut_resource_extension):
186186
"read_write": "y",
187187
"immutable": "y",
188188
"write_only": "y",
189-
}
189+
},
190190
}
191191

192192
assert mut_resource_extension.model_dump(scim_ctx=None, exclude_none=True) == {
@@ -202,7 +202,7 @@ def test_dump_extension(mut_resource_extension):
202202
"read_write": "y",
203203
"immutable": "y",
204204
"write_only": "y",
205-
}
205+
},
206206
}
207207

208208
assert mut_resource_extension.model_dump(by_alias=False) == {
@@ -217,7 +217,7 @@ def test_dump_extension(mut_resource_extension):
217217
"read_write": "y",
218218
"immutable": "y",
219219
"write_only": "y",
220-
}
220+
},
221221
}
222222

223223
assert mut_resource_extension.model_dump(scim_ctx=None, by_alias=True) == {
@@ -235,12 +235,12 @@ def test_dump_extension(mut_resource_extension):
235235
"readWrite": "y",
236236
"immutable": "y",
237237
"writeOnly": "y",
238-
}
238+
},
239239
}
240240

241241

242242
def test_dump_empty_extension(mut_resource_extension_empty):
243-
"""Test dumps with empty extension"""
243+
"""Test dumps with empty extension."""
244244
assert mut_resource_extension_empty.model_dump() == {
245245
"schemas": ["urn:org:example:MutResource", "urn:org:extensions:MutExtension"],
246246
"id": "id",
@@ -265,17 +265,19 @@ def test_dump_empty_extension(mut_resource_extension_empty):
265265
"read_write": None,
266266
"immutable": None,
267267
"write_only": None,
268-
}
268+
},
269269
}
270270

271-
assert mut_resource_extension_empty.model_dump(scim_ctx=None, exclude_none=True) == {
271+
assert mut_resource_extension_empty.model_dump(
272+
scim_ctx=None, exclude_none=True
273+
) == {
272274
"schemas": ["urn:org:example:MutResource", "urn:org:extensions:MutExtension"],
273275
"id": "id",
274276
"read_only": "x",
275277
"read_write": "x",
276278
"immutable": "x",
277279
"write_only": "x",
278-
"MutExtension": {"schemas": ["urn:org:extensions:MutExtension"]}
280+
"MutExtension": {"schemas": ["urn:org:extensions:MutExtension"]},
279281
}
280282

281283
assert mut_resource_extension_empty.model_dump(by_alias=False) == {
@@ -302,7 +304,7 @@ def test_dump_empty_extension(mut_resource_extension_empty):
302304
"readWrite": None,
303305
"immutable": None,
304306
"writeOnly": None,
305-
}
307+
},
306308
}
307309

308310

0 commit comments

Comments
 (0)