soia-client 1.1.0__tar.gz → 1.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of soia-client might be problematic. Click here for more details.

Files changed (34) hide show
  1. {soia_client-1.1.0 → soia_client-1.1.2}/PKG-INFO +1 -1
  2. {soia_client-1.1.0 → soia_client-1.1.2}/pyproject.toml +1 -1
  3. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/enums.py +8 -2
  4. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/structs.py +3 -3
  5. {soia_client-1.1.0 → soia_client-1.1.2}/soia/reflection.py +29 -4
  6. {soia_client-1.1.0 → soia_client-1.1.2}/soia_client.egg-info/PKG-INFO +1 -1
  7. {soia_client-1.1.0 → soia_client-1.1.2}/tests/test_module_initializer.py +11 -2
  8. {soia_client-1.1.0 → soia_client-1.1.2}/LICENSE +0 -0
  9. {soia_client-1.1.0 → soia_client-1.1.2}/README.md +0 -0
  10. {soia_client-1.1.0 → soia_client-1.1.2}/setup.cfg +0 -0
  11. {soia_client-1.1.0 → soia_client-1.1.2}/soia/__init__.py +0 -0
  12. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/__init__.py +0 -0
  13. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/arrays.py +0 -0
  14. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/function_maker.py +0 -0
  15. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/keep.py +0 -0
  16. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/keyed_items.py +0 -0
  17. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/method.py +0 -0
  18. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/never.py +0 -0
  19. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/optionals.py +0 -0
  20. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/primitives.py +0 -0
  21. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/repr.py +0 -0
  22. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/serializer.py +0 -0
  23. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/serializers.py +0 -0
  24. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/service.py +0 -0
  25. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/service_client.py +0 -0
  26. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/timestamp.py +0 -0
  27. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_impl/type_adapter.py +0 -0
  28. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_module_initializer.py +0 -0
  29. {soia_client-1.1.0 → soia_client-1.1.2}/soia/_spec.py +0 -0
  30. {soia_client-1.1.0 → soia_client-1.1.2}/soia_client.egg-info/SOURCES.txt +0 -0
  31. {soia_client-1.1.0 → soia_client-1.1.2}/soia_client.egg-info/dependency_links.txt +0 -0
  32. {soia_client-1.1.0 → soia_client-1.1.2}/soia_client.egg-info/top_level.txt +0 -0
  33. {soia_client-1.1.0 → soia_client-1.1.2}/tests/test_serializers.py +0 -0
  34. {soia_client-1.1.0 → soia_client-1.1.2}/tests/test_timestamp.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Author-email: Tyler Fibonacci <gepheum@gmail.com>
5
5
  License: MIT License
6
6
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "soia-client"
7
- version = "1.1.0"
7
+ version = "1.1.2"
8
8
  description = ""
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Tyler Fibonacci", email = "gepheum@gmail.com" }]
@@ -3,12 +3,11 @@ from collections.abc import Callable, Sequence
3
3
  from dataclasses import FrozenInstanceError, dataclass
4
4
  from typing import Any, Final, Union
5
5
 
6
+ from soia import _spec, reflection
6
7
  from soia._impl.function_maker import BodyBuilder, Expr, ExprLike, Line, make_function
7
8
  from soia._impl.repr import repr_impl
8
9
  from soia._impl.type_adapter import TypeAdapter
9
10
 
10
- from soia import _spec, reflection
11
-
12
11
 
13
12
  class EnumAdapter(TypeAdapter):
14
13
  __slots__ = (
@@ -139,6 +138,13 @@ class EnumAdapter(TypeAdapter):
139
138
  kind="enum",
140
139
  id=record_id,
141
140
  fields=tuple(
141
+ reflection.Field(
142
+ name=field.name,
143
+ number=field.number,
144
+ type=None,
145
+ )
146
+ for field in self.all_constant_fields if field.number != 0
147
+ ) + tuple(
142
148
  reflection.Field(
143
149
  name=field.spec.name,
144
150
  number=field.spec.number,
@@ -429,7 +429,7 @@ def _make_replace_method(
429
429
  """
430
430
 
431
431
  keep_local = Expr.local("KEEP", KEEP)
432
- params: Params = []
432
+ params: Params = ["_self"]
433
433
  if fields:
434
434
  params.append("*")
435
435
  params.extend(
@@ -442,7 +442,7 @@ def _make_replace_method(
442
442
 
443
443
  def field_to_arg_assigment(attr: str) -> LineSpan:
444
444
  return LineSpan.join(
445
- f"{attr}=self.{attr} if {attr} is ", keep_local, " else {attr}"
445
+ f"{attr}=_self.{attr} if {attr} is ", keep_local, f" else {attr}"
446
446
  )
447
447
 
448
448
  builder = BodyBuilder()
@@ -458,7 +458,7 @@ def _make_replace_method(
458
458
  )
459
459
 
460
460
  return make_function(
461
- name="partial",
461
+ name="replace",
462
462
  params=params,
463
463
  body=builder.build(),
464
464
  )
@@ -109,11 +109,19 @@ class _Serializer(Generic[_T]):
109
109
  from_json: Callable[[Any], _T]
110
110
 
111
111
 
112
+ @dataclass(frozen=True, eq=True)
113
+ class _NoDefault:
114
+ pass
115
+
116
+
117
+ _NO_DEFAULT: Final = _NoDefault()
118
+
119
+
112
120
  @dataclass(frozen=True)
113
121
  class _FieldSerializer(Generic[_T]):
114
122
  name: str
115
123
  serializer: _Serializer[_T]
116
- default: Optional[_T] = None
124
+ default: _T | _NoDefault = _NO_DEFAULT
117
125
 
118
126
 
119
127
  def _primitive_serializer(check_type_fn: Callable[[Any], _T]) -> _Serializer[_T]:
@@ -144,7 +152,7 @@ def _dataclass_serializer(
144
152
  def field_from_json(field: _FieldSerializer) -> Any:
145
153
  value_json = json.get(field.name)
146
154
  if value_json is None:
147
- if field.default is not None:
155
+ if field.default != _NO_DEFAULT:
148
156
  return field.default
149
157
  else:
150
158
  # Will raise an exception.
@@ -196,6 +204,22 @@ def _forwarding_serializer(
196
204
  return _Serializer(to_json, from_json)
197
205
 
198
206
 
207
+ def _optional_serializer(
208
+ other_serializer: _Serializer[_T],
209
+ ) -> _Serializer[Optional[_T]]:
210
+ def to_json(input: Optional[_T]) -> Any:
211
+ if input is None:
212
+ return None
213
+ return other_serializer.to_json(input)
214
+
215
+ def from_json(json: Any) -> Optional[_T]:
216
+ if json is None:
217
+ return None
218
+ return other_serializer.from_json(json)
219
+
220
+ return _Serializer(to_json, from_json)
221
+
222
+
199
223
  # ==============================================================================
200
224
  # INTERNAL: JSON serialization of TypeDescriptor
201
225
  # ==============================================================================
@@ -292,9 +316,10 @@ _FIELD_SERIALIZER: Final = _dataclass_serializer(
292
316
  "name",
293
317
  _primitive_serializer(str),
294
318
  ),
295
- _FieldSerializer(
319
+ _FieldSerializer[Optional[Type]](
296
320
  "type",
297
- _forwarding_serializer(_type_serializer),
321
+ _optional_serializer(_forwarding_serializer(_type_serializer)),
322
+ default=None,
298
323
  ),
299
324
  _FieldSerializer(
300
325
  "number",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Author-email: Tyler Fibonacci <gepheum@gmail.com>
5
5
  License: MIT License
6
6
 
@@ -2,11 +2,10 @@ import dataclasses
2
2
  import unittest
3
3
  from typing import Any
4
4
 
5
+ from soia import KeyedItems, Method, Timestamp, _spec
5
6
  from soia._module_initializer import init_module
6
7
  from soia.reflection import TypeDescriptor
7
8
 
8
- from soia import KeyedItems, Method, Timestamp, _spec
9
-
10
9
 
11
10
  class ModuleInitializerTestCase(unittest.TestCase):
12
11
  def init_test_module(self) -> dict[str, Any]:
@@ -369,6 +368,12 @@ class ModuleInitializerTestCase(unittest.TestCase):
369
368
  self.assertEqual(point.x, 1.5)
370
369
  self.assertEqual(point.y, 0.0)
371
370
 
371
+ def test_replace(self):
372
+ point_cls = self.init_test_module()["Point"]
373
+ point = point_cls(x=1.5, y=2.5).replace(y=3.5)
374
+ self.assertEqual(point.x, 1.5)
375
+ self.assertEqual(point.y, 3.5)
376
+
372
377
  def test_to_mutable(self):
373
378
  point_cls = self.init_test_module()["Point"]
374
379
  point = point_cls(x=1.5, y=2.5)
@@ -1195,6 +1200,10 @@ class ModuleInitializerTestCase(unittest.TestCase):
1195
1200
  "kind": "enum",
1196
1201
  "id": "my/module.soia:JsonValue",
1197
1202
  "fields": [
1203
+ {
1204
+ "name": "NULL",
1205
+ "number": 1,
1206
+ },
1198
1207
  {
1199
1208
  "name": "bool",
1200
1209
  "type": {"kind": "primitive", "value": "bool"},
File without changes
File without changes
File without changes
File without changes