soia-client 1.1.3__py3-none-any.whl → 1.1.5__py3-none-any.whl

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.
soia/_impl/arrays.py CHANGED
@@ -3,12 +3,11 @@ from dataclasses import FrozenInstanceError
3
3
  from typing import Generic, Optional
4
4
  from weakref import WeakValueDictionary
5
5
 
6
+ from soia import _spec, reflection
6
7
  from soia._impl.function_maker import Any, Expr, ExprLike, Line, make_function
7
8
  from soia._impl.keyed_items import Item, Key, KeyedItems
8
9
  from soia._impl.type_adapter import TypeAdapter
9
10
 
10
- from soia import _spec, reflection
11
-
12
11
 
13
12
  def get_array_adapter(
14
13
  item_adapter: TypeAdapter,
@@ -123,6 +122,9 @@ class _ArrayAdapter(TypeAdapter):
123
122
  ) -> None:
124
123
  self.item_adapter.register_records(registry)
125
124
 
125
+ def frozen_class_of_struct(self) -> type | None:
126
+ return None
127
+
126
128
 
127
129
  _ItemAndKeyAttributes = tuple[TypeAdapter, tuple[str, ...]]
128
130
  _ItemToArrayAdapter = WeakValueDictionary[_ItemAndKeyAttributes, _ArrayAdapter]
soia/_impl/enums.py CHANGED
@@ -73,6 +73,12 @@ class EnumAdapter(TypeAdapter):
73
73
  for value_field in value_fields:
74
74
  wrap_fn = _make_wrap_fn(value_field)
75
75
  setattr(base_class, f"wrap_{value_field.spec.name}", wrap_fn)
76
+ # Check if the field type is a struct type.
77
+ field_type = resolve_type_fn(value_field.spec.type)
78
+ frozen_class = field_type.frozen_class_of_struct()
79
+ if frozen_class:
80
+ create_fn = _make_create_fn(wrap_fn, frozen_class)
81
+ setattr(base_class, f"create_{value_field.spec.name}", create_fn)
76
82
 
77
83
  base_class._fj = _make_from_json_fn(
78
84
  self.all_constant_fields,
@@ -143,8 +149,10 @@ class EnumAdapter(TypeAdapter):
143
149
  number=field.number,
144
150
  type=None,
145
151
  )
146
- for field in self.all_constant_fields if field.number != 0
147
- ) + tuple(
152
+ for field in self.all_constant_fields
153
+ if field.number != 0
154
+ )
155
+ + tuple(
148
156
  reflection.Field(
149
157
  name=field.spec.name,
150
158
  number=field.spec.number,
@@ -157,6 +165,9 @@ class EnumAdapter(TypeAdapter):
157
165
  for field in self.value_fields:
158
166
  field.field_type.register_records(registry)
159
167
 
168
+ def frozen_class_of_struct(self) -> type | None:
169
+ return None
170
+
160
171
 
161
172
  def _make_base_class(spec: _spec.Enum) -> type:
162
173
  record_hash = hash(spec.id)
@@ -174,6 +185,9 @@ def _make_base_class(spec: _spec.Enum) -> type:
174
185
  def union(self) -> Any:
175
186
  return self
176
187
 
188
+ def __bool__(self) -> bool:
189
+ return self.kind != "?"
190
+
177
191
  def __setattr__(self, name: str, value: Any):
178
192
  raise FrozenInstanceError(self.__class__.__qualname__)
179
193
 
@@ -344,6 +358,13 @@ def _make_wrap_fn(field: _ValueField) -> Callable[[Any], Any]:
344
358
  )
345
359
 
346
360
 
361
+ def _make_create_fn(wrap_fn: Callable[[Any], Any], frozen_class: type) -> Callable:
362
+ def create(**kwargs):
363
+ return wrap_fn(frozen_class(**kwargs))
364
+
365
+ return create
366
+
367
+
347
368
  def _make_from_json_fn(
348
369
  constant_fields: Sequence[_spec.ConstantField],
349
370
  value_fields: Sequence[_ValueField],
soia/_impl/optionals.py CHANGED
@@ -3,11 +3,10 @@ from dataclasses import dataclass
3
3
  from typing import TypeVar
4
4
  from weakref import WeakValueDictionary
5
5
 
6
+ from soia import _spec, reflection
6
7
  from soia._impl.function_maker import Expr, ExprLike
7
8
  from soia._impl.type_adapter import TypeAdapter
8
9
 
9
- from soia import _spec, reflection
10
-
11
10
  Other = TypeVar("Other")
12
11
 
13
12
 
@@ -80,6 +79,9 @@ class _OptionalAdapter(TypeAdapter):
80
79
  ) -> None:
81
80
  self.other_adapter.register_records(registry)
82
81
 
82
+ def frozen_class_of_struct(self) -> type | None:
83
+ return None
84
+
83
85
 
84
86
  _other_adapter_to_optional_adapter: WeakValueDictionary[TypeAdapter, TypeAdapter] = (
85
87
  WeakValueDictionary()
soia/_impl/primitives.py CHANGED
@@ -3,12 +3,11 @@ from collections.abc import Callable
3
3
  from dataclasses import dataclass
4
4
  from typing import Any, Final, final
5
5
 
6
+ from soia import _spec, reflection
6
7
  from soia._impl.function_maker import Expr, ExprLike
7
8
  from soia._impl.timestamp import Timestamp
8
9
  from soia._impl.type_adapter import TypeAdapter
9
10
 
10
- from soia import _spec, reflection
11
-
12
11
 
13
12
  class AbstractPrimitiveAdapter(TypeAdapter):
14
13
  @final
@@ -25,6 +24,10 @@ class AbstractPrimitiveAdapter(TypeAdapter):
25
24
  ) -> None:
26
25
  pass
27
26
 
27
+ @final
28
+ def frozen_class_of_struct(self) -> type | None:
29
+ return None
30
+
28
31
 
29
32
  class _BoolAdapter(AbstractPrimitiveAdapter):
30
33
  def default_expr(self) -> ExprLike:
soia/_impl/repr.py CHANGED
@@ -10,7 +10,7 @@ class ReprResult:
10
10
 
11
11
  @property
12
12
  def indented(self) -> str:
13
- if complex:
13
+ if self.complex:
14
14
  return self.repr.replace("\n", "\n ")
15
15
  else:
16
16
  return self.repr
soia/_impl/serializer.py CHANGED
@@ -5,12 +5,11 @@ from functools import cached_property
5
5
  from typing import Any, Generic, TypeVar, cast, final
6
6
  from weakref import WeakValueDictionary
7
7
 
8
+ from soia import reflection
8
9
  from soia._impl.function_maker import Expr, LineSpan, make_function
9
10
  from soia._impl.never import Never
10
11
  from soia._impl.type_adapter import TypeAdapter
11
12
 
12
- from soia import reflection
13
-
14
13
  T = TypeVar("T")
15
14
 
16
15
 
soia/_impl/service.py CHANGED
@@ -61,7 +61,7 @@ _RESTUDIO_HTML = """<!DOCTYPE html>
61
61
  <head>
62
62
  <meta charset="utf-8" />
63
63
  <title>RESTudio</title>
64
- <script src="dist/restudio-standalone.js"></script>
64
+ <script src="https://cdn.jsdelivr.net/npm/restudio/dist/restudio-standalone.js"></script>
65
65
  </head>
66
66
  <body style="margin: 0; padding: 0;">
67
67
  <restudio-app></restudio-app>
@@ -160,5 +160,4 @@ class _AiohttpClientSession(Protocol):
160
160
  *,
161
161
  data: str,
162
162
  headers: Mapping[str, str],
163
- ) -> Any:
164
- ...
163
+ ) -> Any: ...
soia/_impl/structs.py CHANGED
@@ -3,6 +3,7 @@ from collections.abc import Callable, Sequence
3
3
  from dataclasses import FrozenInstanceError, dataclass
4
4
  from typing import Any, Final, Union, cast
5
5
 
6
+ from soia import _spec, reflection
6
7
  from soia._impl.function_maker import (
7
8
  BodyBuilder,
8
9
  Expr,
@@ -18,8 +19,6 @@ from soia._impl.keep import KEEP
18
19
  from soia._impl.repr import repr_impl
19
20
  from soia._impl.type_adapter import TypeAdapter
20
21
 
21
- from soia import _spec, reflection
22
-
23
22
 
24
23
  class StructAdapter(TypeAdapter):
25
24
  __slots__ = (
@@ -236,6 +235,9 @@ class StructAdapter(TypeAdapter):
236
235
  for field in self.fields:
237
236
  field.type.register_records(registry)
238
237
 
238
+ def frozen_class_of_struct(self) -> type | None:
239
+ return self.gen_class
240
+
239
241
 
240
242
  class _Frozen:
241
243
  def __setattr__(self, name: str, value: Any):
@@ -1,9 +1,8 @@
1
1
  from collections.abc import Callable
2
2
  from typing import Protocol
3
3
 
4
- from soia._impl.function_maker import ExprLike
5
-
6
4
  from soia import _spec, reflection
5
+ from soia._impl.function_maker import ExprLike
7
6
 
8
7
 
9
8
  class TypeAdapter(Protocol):
@@ -1,11 +1,10 @@
1
1
  from typing import Any, Union
2
2
 
3
+ from soia import _spec
3
4
  from soia._impl import arrays, enums, method, optionals, primitives, structs
4
5
  from soia._impl.serializer import make_serializer
5
6
  from soia._impl.type_adapter import TypeAdapter
6
7
 
7
- from soia import _spec
8
-
9
8
  RecordAdapter = Union[structs.StructAdapter, enums.EnumAdapter]
10
9
 
11
10
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: soia-client
3
- Version: 1.1.3
3
+ Version: 1.1.5
4
4
  Author-email: Tyler Fibonacci <gepheum@gmail.com>
5
5
  License: MIT License
6
6
 
@@ -0,0 +1,27 @@
1
+ soia/__init__.py,sha256=WPhdlu7zKBSWd4DVFWXQKQoptD0gU7xGFm4tbQHrVc8,787
2
+ soia/_module_initializer.py,sha256=JHZMcLqpYuWoC3cN4wBFFCHlHR60-LNvrjo_EMCFkAE,4220
3
+ soia/_spec.py,sha256=Y5EHHQa6qNeJc29aaqGrFPnPFXxlL7TED9_AXUGBjf0,3663
4
+ soia/reflection.py,sha256=SEFHNlzmWZEOQwoVUTIxzjjnbkiKSwo2rbpSU-qXhC4,9375
5
+ soia/_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ soia/_impl/arrays.py,sha256=Dz0_huUdtCtT6TP2R5IY6vNbZ8RJPx3l1Sa3pdbyVAA,5550
7
+ soia/_impl/enums.py,sha256=Z5oGNCVsPIlGP1D0BZTkYWLehDt5HKJ840lsMQSW0xQ,18011
8
+ soia/_impl/function_maker.py,sha256=MvCDv1WwzKGJzZbNCnJ_8-MP3m1xTIabumXA-9Ydd9M,5639
9
+ soia/_impl/keep.py,sha256=GDeMKKUcvUFXWJVzBPB9CuLkcQb93sWKvo0PcyKUBzg,370
10
+ soia/_impl/keyed_items.py,sha256=EoPrdeLJ8i7zCH-oW-7qOcyadyrzykB6lkrf3xRVmyk,337
11
+ soia/_impl/method.py,sha256=C6ygh-Li4zADxFR_gfeBTuPUzLjZ1XHCp0ZI4-uiRYs,455
12
+ soia/_impl/never.py,sha256=T7PHtIipuXlici4wa0yuJKrn9JgcT-ODC3QVCwsPprY,46
13
+ soia/_impl/optionals.py,sha256=hnr3itvScPEbMq--Z8yC3Qs2OFDy8l5Ljd5BSnsCIn4,2487
14
+ soia/_impl/primitives.py,sha256=rQUit2EVXr36RK5cW7x9TaZTJ9w1oHcXmVr0mTlyBO0,9109
15
+ soia/_impl/repr.py,sha256=Z4sZKFrujdTD49aqB7q3bjXAb1f31I7uuChDBy5XvFg,1418
16
+ soia/_impl/serializer.py,sha256=RBYz-9Kc-sKR0YEhX48w8oA5uK4yJ1DbhqUwOzYrT5E,3528
17
+ soia/_impl/serializers.py,sha256=IL9jHHMo11pgrL1-crarOEElvTyV5YM6FTcgumjW6IU,2564
18
+ soia/_impl/service.py,sha256=ltOCPJupK3mEDiq9wldkDb0rfpVhyqWFxywGJ42Vklg,15573
19
+ soia/_impl/service_client.py,sha256=FWfbFswbhMBw1snR9JLEpSJagY2ntZbFaVxTUGEDA5s,5303
20
+ soia/_impl/structs.py,sha256=ed2B-viBclbc4DbXJ-0mNaS1NyM0vURuGnU-H3LFUik,28313
21
+ soia/_impl/timestamp.py,sha256=upnEkvW-7AaMJ9_nNqntvhJ4pFWWCAXNjEOPtszdwgE,5645
22
+ soia/_impl/type_adapter.py,sha256=5ilurqFQ0fcw7ciYdkLbzH65Qz0SJwHMbqFqywkRUUE,2100
23
+ soia_client-1.1.5.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
24
+ soia_client-1.1.5.dist-info/METADATA,sha256=oTvY4awlTRAC5vSFmLQyVVA8-yz_kpPTTe9K5dV3Utg,2121
25
+ soia_client-1.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
+ soia_client-1.1.5.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
27
+ soia_client-1.1.5.dist-info/RECORD,,
@@ -1,27 +0,0 @@
1
- soia/__init__.py,sha256=WPhdlu7zKBSWd4DVFWXQKQoptD0gU7xGFm4tbQHrVc8,787
2
- soia/_module_initializer.py,sha256=1TWnc0qUO7_iljQR2ywVERrrkY5jIkT3zucc-AYZyrQ,4221
3
- soia/_spec.py,sha256=Y5EHHQa6qNeJc29aaqGrFPnPFXxlL7TED9_AXUGBjf0,3663
4
- soia/reflection.py,sha256=SEFHNlzmWZEOQwoVUTIxzjjnbkiKSwo2rbpSU-qXhC4,9375
5
- soia/_impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- soia/_impl/arrays.py,sha256=C3j3RZdSvqmogbGAi3EprLkUYMFfO-IJhoCOte5blAw,5477
7
- soia/_impl/enums.py,sha256=bpRtIWBioTGpy-oVA5Fo25RZH1TFBFzrmCXkuhZuC0k,17297
8
- soia/_impl/function_maker.py,sha256=MvCDv1WwzKGJzZbNCnJ_8-MP3m1xTIabumXA-9Ydd9M,5639
9
- soia/_impl/keep.py,sha256=GDeMKKUcvUFXWJVzBPB9CuLkcQb93sWKvo0PcyKUBzg,370
10
- soia/_impl/keyed_items.py,sha256=EoPrdeLJ8i7zCH-oW-7qOcyadyrzykB6lkrf3xRVmyk,337
11
- soia/_impl/method.py,sha256=C6ygh-Li4zADxFR_gfeBTuPUzLjZ1XHCp0ZI4-uiRYs,455
12
- soia/_impl/never.py,sha256=T7PHtIipuXlici4wa0yuJKrn9JgcT-ODC3QVCwsPprY,46
13
- soia/_impl/optionals.py,sha256=KTgmbfYLJLrju5v10jgnnnW98QG6NYw2We3gdgi9i2E,2414
14
- soia/_impl/primitives.py,sha256=r-55rO12TwwWCQJgzEEgVpXMVGg0dRhGvFWX_rGeqsQ,9025
15
- soia/_impl/repr.py,sha256=7WX0bEAVENTjlyZIcbT8TcJylS7IRIyafGCmqaIMxFM,1413
16
- soia/_impl/serializer.py,sha256=28IwkjtUnLpbnPQfVNfJXkApCK4JhXHwLkC5MVhF8xo,3529
17
- soia/_impl/serializers.py,sha256=IL9jHHMo11pgrL1-crarOEElvTyV5YM6FTcgumjW6IU,2564
18
- soia/_impl/service.py,sha256=zwxbFojyyrFm8_xc8PN8xMmMKPqC92BarUjhxYza5Hc,15535
19
- soia/_impl/service_client.py,sha256=0WgiN6Stg548FAdZQMuezZoooe4MYw2frEQ5KUE7xag,5311
20
- soia/_impl/structs.py,sha256=1XhjZmqtD7IMURdSVR0DwMdrIhWPZft1eCfwVW84c0E,28230
21
- soia/_impl/timestamp.py,sha256=upnEkvW-7AaMJ9_nNqntvhJ4pFWWCAXNjEOPtszdwgE,5645
22
- soia/_impl/type_adapter.py,sha256=RyIyh4Fnt9rMy0HRzC-a2v2JAdZsV9FBzoGEUVygVRE,2101
23
- soia_client-1.1.3.dist-info/licenses/LICENSE,sha256=SaAftKkX6hfSOiPdENQPS70tifH3PDHgazq8eK2Pwfw,1064
24
- soia_client-1.1.3.dist-info/METADATA,sha256=kDuwtQ-gADi4JKDkYk_ZtRJPRJR4qiHb9fylrWoeAzA,2121
25
- soia_client-1.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
26
- soia_client-1.1.3.dist-info/top_level.txt,sha256=lsYG9JrvauFe1oIV5zvnwsS9hsx3ztwfK_937op9mxc,5
27
- soia_client-1.1.3.dist-info/RECORD,,