localstack-py-avro-schema 3.9.4__tar.gz → 3.9.6__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.
Files changed (39) hide show
  1. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/PKG-INFO +1 -1
  2. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/localstack_py_avro_schema.egg-info/PKG-INFO +1 -1
  3. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/_schemas.py +35 -1
  4. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_primitives.py +47 -1
  5. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.editorconfig +0 -0
  6. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.flake8 +0 -0
  7. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.github/workflows/release-package.yml +0 -0
  8. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.github/workflows/test-package.yml +0 -0
  9. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.gitignore +0 -0
  10. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.pre-commit-config.yaml +0 -0
  11. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/.readthedocs.yaml +0 -0
  12. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/LICENSE +0 -0
  13. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/LICENSE_HEADER.txt +0 -0
  14. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/README.md +0 -0
  15. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/conf.py +0 -0
  16. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/index.rst +0 -0
  17. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/modules.rst +0 -0
  18. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/py_avro_schema.rst +0 -0
  19. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/tutorial.rst +0 -0
  20. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/docs/types.rst +0 -0
  21. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/pyproject.toml +0 -0
  22. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/setup.cfg +0 -0
  23. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/localstack_py_avro_schema.egg-info/SOURCES.txt +0 -0
  24. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/localstack_py_avro_schema.egg-info/dependency_links.txt +0 -0
  25. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/localstack_py_avro_schema.egg-info/requires.txt +0 -0
  26. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/localstack_py_avro_schema.egg-info/top_level.txt +0 -0
  27. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/__init__.py +0 -0
  28. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/_alias.py +0 -0
  29. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/_testing.py +0 -0
  30. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/_typing.py +0 -0
  31. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/src/py_avro_schema/py.typed +0 -0
  32. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_avro_schema.py +0 -0
  33. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_dataclass.py +0 -0
  34. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_logicals.py +0 -0
  35. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_plain_class.py +0 -0
  36. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_pydantic.py +0 -0
  37. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_typed_dict.py +0 -0
  38. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tests/test_typing.py +0 -0
  39. {localstack_py_avro_schema-3.9.4 → localstack_py_avro_schema-3.9.6}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-py-avro-schema
3
- Version: 3.9.4
3
+ Version: 3.9.6
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: localstack-py-avro-schema
3
- Version: 3.9.4
3
+ Version: 3.9.6
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
@@ -671,6 +671,33 @@ class SequenceSchema(Schema):
671
671
  return [self.items_schema.make_default(item) for item in py_default]
672
672
 
673
673
 
674
+ @register_schema
675
+ class SetSchema(SequenceSchema):
676
+ """An Avro array schema for a given Python set"""
677
+
678
+ @classmethod
679
+ def handles_type(cls, py_type: type) -> bool:
680
+ """Whether this schema class can represent a given Python class"""
681
+ py_type = _type_from_annotated(py_type)
682
+ origin = get_origin(py_type)
683
+ return _is_class(origin, collections.abc.MutableSet)
684
+
685
+ def __init__(
686
+ self,
687
+ py_type: type[collections.abc.MutableSet],
688
+ namespace: str | None = None,
689
+ options: Option = Option(0),
690
+ ):
691
+ """
692
+ An Avro array schema for a given Python sequence
693
+
694
+ :param py_type: The Python class to generate a schema for.
695
+ :param namespace: The Avro namespace to add to schemas.
696
+ :param options: Schema generation options.
697
+ """
698
+ super().__init__(py_type, namespace=namespace, options=options) # type: ignore
699
+
700
+
674
701
  @register_schema
675
702
  class DictSchema(Schema):
676
703
  """An Avro map schema for a given Python mapping"""
@@ -860,6 +887,13 @@ class EnumSchema(NamedSchema):
860
887
  return False
861
888
  return True
862
889
 
890
+ def data(self, names: NamesType) -> JSONType:
891
+ """Return the schema data"""
892
+ # For invalid enums we don't want to deduplicate the data
893
+ if not self._is_valid_enum():
894
+ return self.data_before_deduplication(names=names)
895
+ return super().data(names)
896
+
863
897
  def data_before_deduplication(self, names: NamesType) -> JSONObj:
864
898
  """Return the schema data"""
865
899
  if not self._is_valid_enum():
@@ -1141,7 +1175,7 @@ class PlainClassSchema(RecordSchema):
1141
1175
  if field := self.signature_fields.get(name):
1142
1176
  _annotation, _default = field
1143
1177
  if actual_type is _annotation:
1144
- default = _default
1178
+ default = _default or dataclasses.MISSING
1145
1179
  field_obj = RecordField(
1146
1180
  py_type=actual_type,
1147
1181
  name=name,
@@ -8,7 +8,7 @@
8
8
  # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
9
9
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
10
  # specific language governing permissions and limitations under the License.
11
-
11
+ import dataclasses
12
12
  import enum
13
13
  import re
14
14
  import sys
@@ -174,6 +174,12 @@ def test_string_list():
174
174
  assert_schema(py_type, expected)
175
175
 
176
176
 
177
+ def test_string_set():
178
+ py_type = set[str]
179
+ expected = {"type": "array", "items": "string"}
180
+ assert_schema(py_type, expected)
181
+
182
+
177
183
  def test_string_list_annotated():
178
184
  py_type = Annotated[List[str], ...]
179
185
  expected = {"type": "array", "items": "string"}
@@ -192,6 +198,12 @@ def test_int_list():
192
198
  assert_schema(py_type, expected)
193
199
 
194
200
 
201
+ def test_int_set():
202
+ py_type = set[int]
203
+ expected = {"type": "array", "items": "long"}
204
+ assert_schema(py_type, expected)
205
+
206
+
195
207
  def test_string_tuple():
196
208
  py_type = Tuple[str]
197
209
  expected = {"type": "array", "items": "string"}
@@ -214,6 +226,18 @@ def test_string_mutable_sequence():
214
226
  assert_schema(py_type, expected)
215
227
 
216
228
 
229
+ def test_string_set_of_set():
230
+ py_type = set[set[str]]
231
+ expected = {
232
+ "type": "array",
233
+ "items": {
234
+ "type": "array",
235
+ "items": "string",
236
+ },
237
+ }
238
+ assert_schema(py_type, expected)
239
+
240
+
217
241
  def test_string_list_of_lists():
218
242
  py_type = List[List[str]]
219
243
  expected = {
@@ -519,3 +543,25 @@ def test_str_enum_invalid_name():
519
543
  expected = {"namedString": "OriginProtocolPolicy", "type": "string"}
520
544
 
521
545
  assert_schema(OriginProtocolPolicy, expected)
546
+
547
+
548
+ def test_duplicated_invalid_enum():
549
+ class OriginProtocolPolicy(str, enum.Enum):
550
+ http_only = "http-only"
551
+ match_viewer = "match-viewer"
552
+ https_only = "https-only"
553
+
554
+ @dataclasses.dataclass
555
+ class PyType:
556
+ enum_one: OriginProtocolPolicy
557
+ enum_two: OriginProtocolPolicy
558
+
559
+ expected = {
560
+ "type": "record",
561
+ "name": "PyType",
562
+ "fields": [
563
+ {"type": {"type": "string", "namedString": "OriginProtocolPolicy"}, "name": "enum_one"},
564
+ {"type": {"type": "string", "namedString": "OriginProtocolPolicy"}, "name": "enum_two"},
565
+ ],
566
+ }
567
+ assert_schema(PyType, expected)