localstack-py-avro-schema 3.9.3__py3-none-any.whl → 3.9.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-py-avro-schema
3
- Version: 3.9.3
3
+ Version: 3.9.4
4
4
  Summary: Generate Apache Avro schemas for Python types including standard library data-classes and Pydantic data models.
5
5
  Author-email: LocalStack Contributors <info@localstack.cloud>, "J.P. Morgan Chase & Co." <open_source@jpmorgan.com>
6
6
  License: Apache License
@@ -1,12 +1,12 @@
1
- localstack_py_avro_schema-3.9.3.dist-info/licenses/LICENSE,sha256=zE1N4JILDTkSIDtdmqdnKKxKEQh_VdqeoAV2230eNOI,10141
2
- localstack_py_avro_schema-3.9.3.dist-info/licenses/LICENSE_HEADER.txt,sha256=Nx3RGmYbJKjIKM8Y2yMrCPJgCw4oBt_H62PxDKlAsto,564
1
+ localstack_py_avro_schema-3.9.4.dist-info/licenses/LICENSE,sha256=zE1N4JILDTkSIDtdmqdnKKxKEQh_VdqeoAV2230eNOI,10141
2
+ localstack_py_avro_schema-3.9.4.dist-info/licenses/LICENSE_HEADER.txt,sha256=Nx3RGmYbJKjIKM8Y2yMrCPJgCw4oBt_H62PxDKlAsto,564
3
3
  py_avro_schema/__init__.py,sha256=bK6hTw4XJy5bAP4lgIvJR5LHtEiyUWq4GNJ5w-uSEpc,2414
4
4
  py_avro_schema/_alias.py,sha256=nCQqtn7IbpjV0ibpJf9aMX9FvwVx2EDC1iKzwjQ7CqI,3412
5
- py_avro_schema/_schemas.py,sha256=uUyztznCjmIescXDWEFetwAgBZ0mAIdGHpdea1EEY9k,48182
5
+ py_avro_schema/_schemas.py,sha256=L9_c-I1ihS9BJpXe1-foDMUppxY7PyTT544hMbrS1TM,48589
6
6
  py_avro_schema/_testing.py,sha256=3aSfMbNDDeatl3H7GEUcynxK81HFiF-WCLOZ3FCCLiw,2261
7
7
  py_avro_schema/_typing.py,sha256=9kBlPA7C33zZP3nRhCvSJA_0m54uvUo0AQ4wJJmSxMk,3291
8
8
  py_avro_schema/py.typed,sha256=HnEDkaznpgfRW07Qfogy4tFLu_4dcQ5YcOsI7pmU5rQ,52
9
- localstack_py_avro_schema-3.9.3.dist-info/METADATA,sha256=hykDGJcbbKVESlOoQ3zQFWlSQ8KAv9JA18_y_AIhv6o,15164
10
- localstack_py_avro_schema-3.9.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- localstack_py_avro_schema-3.9.3.dist-info/top_level.txt,sha256=0t4oO_5rsdfZGSk8iSzK4TjdyfVz-RE1IZ2TIz6YvI0,15
12
- localstack_py_avro_schema-3.9.3.dist-info/RECORD,,
9
+ localstack_py_avro_schema-3.9.4.dist-info/METADATA,sha256=2VBFpx5j-KsRbwOmtIICNMNLSgB34kwkCra0Jh_WO5U,15164
10
+ localstack_py_avro_schema-3.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ localstack_py_avro_schema-3.9.4.dist-info/top_level.txt,sha256=0t4oO_5rsdfZGSk8iSzK4TjdyfVz-RE1IZ2TIz6YvI0,15
12
+ localstack_py_avro_schema-3.9.4.dist-info/RECORD,,
@@ -137,9 +137,10 @@ JSON_OPTIONS = [opt for opt in Option if opt.name and opt.name.startswith("JSON_
137
137
  _SCHEMA_CLASSES = []
138
138
 
139
139
 
140
- def register_schema(cls):
140
+ def register_schema(cls: type | None = None, *, priority: int = 0):
141
141
  """
142
142
  Decorator to register a class as a known ``Schema``
143
+ It also accept a priority value to sort the list of schemas. Default schemas have priority 0.
143
144
 
144
145
  Schema classes are instantiated when calling ``schema``. Example use::
145
146
 
@@ -149,10 +150,15 @@ def register_schema(cls):
149
150
  def handles_type(cls, py_type: Type) -> bool:
150
151
  ...
151
152
  ...
152
-
153
153
  """
154
- _SCHEMA_CLASSES.append(cls)
155
- return cls
154
+
155
+ def _wrapper(_cls):
156
+ """Wrapper function to attach priority and sort the list of schemas."""
157
+ _cls.__py_avro_priority = priority
158
+ _SCHEMA_CLASSES.append(_cls)
159
+ return _cls
160
+
161
+ return _wrapper if not cls else _wrapper(cls)
156
162
 
157
163
 
158
164
  def schema(
@@ -188,7 +194,7 @@ def _schema_obj(py_type: Type, namespace: Optional[str] = None, options: Option
188
194
  :param options: Schema generation options.
189
195
  """
190
196
  # Find concrete Schema subclasses defined in the current module
191
- for schema_class in _SCHEMA_CLASSES:
197
+ for schema_class in sorted(_SCHEMA_CLASSES, key=lambda c: getattr(c, "__py_avro_priority", 0)):
192
198
  # Find the first schema class that handles py_type
193
199
  schema_obj = schema_class(py_type, namespace=namespace, options=options) # type: ignore
194
200
  if schema_obj: