change API function name
MODIFY
fastavro/_schema.pyi
fastavro/_schema.pyi
@@ -9,4 +9,4 @@ def parse_schema(
def fullname(schema: Dict) -> str: ...
def expand_schema(schema: Dict) -> Dict: ...
def load_schema_ordered(ordered_schemas: List[str]) -> Dict: ...
-def to_canonical_form(schema: SchemaType) -> str: ...
+def to_parsing_canonical_form(schema: SchemaType) -> str: ...

MODIFY
fastavro/_schema.pyx
fastavro/_schema.pyx
@@ -428,20 +428,20 @@ def load_schema_ordered(ordered_schemas, *, _write_hint=True):
return outer_schema
-def to_canonical_form(schema):
+def to_parsing_canonical_form(schema):
fo = StringIO()
- _to_canonical_form(parse_schema(schema), fo)
+ _to_parsing_canonical_form(parse_schema(schema), fo)
return fo.getvalue()
-cdef _to_canonical_form(schema, fo):
+cdef _to_parsing_canonical_form(schema, fo):
# union schemas
if isinstance(schema, list):
fo.write("[")
for idx, s in enumerate(schema):
if idx != 0:
fo.write(",")
- _to_canonical_form(s, fo)
+ _to_parsing_canonical_form(s, fo)
fo.write("]")
# string schemas; this could be either a named schema or a primitive type
@@ -454,12 +454,12 @@ cdef _to_canonical_form(schema, fo):
if schema_type == "array":
fo.write(f'{{"type":"{schema_type}","items":')
- _to_canonical_form(schema["items"], fo)
+ _to_parsing_canonical_form(schema["items"], fo)
fo.write("}")
elif schema_type == "map":
fo.write(f'{{"type":"{schema_type}","values":')
- _to_canonical_form(schema["values"], fo)
+ _to_parsing_canonical_form(schema["values"], fo)
fo.write("}")
elif schema_type == "enum":
@@ -486,7 +486,7 @@ cdef _to_canonical_form(schema, fo):
fo.write(",")
name = field["name"]
fo.write(f'{{"name":"{name}","type":')
- _to_canonical_form(field["type"], fo)
+ _to_parsing_canonical_form(field["type"], fo)
fo.write("}")
fo.write("]}")

MODIFY
fastavro/_schema_py.py
fastavro/_schema_py.py
@@ -658,20 +658,20 @@ def load_schema_ordered(ordered_schemas, *, _write_hint=True):
return outer_schema
-def to_canonical_form(schema):
+def to_parsing_canonical_form(schema):
fo = StringIO()
- _to_canonical_form(parse_schema(schema), fo)
+ _to_parsing_canonical_form(parse_schema(schema), fo)
return fo.getvalue()
-def _to_canonical_form(schema, fo):
+def _to_parsing_canonical_form(schema, fo):
# union schemas
if isinstance(schema, list):
fo.write("[")
for idx, s in enumerate(schema):
if idx != 0:
fo.write(",")
- _to_canonical_form(s, fo)
+ _to_parsing_canonical_form(s, fo)
fo.write("]")
# string schemas; this could be either a named schema or a primitive type
@@ -684,12 +684,12 @@ def _to_canonical_form(schema, fo):
if schema_type == "array":
fo.write(f'{{"type":"{schema_type}","items":')
- _to_canonical_form(schema["items"], fo)
+ _to_parsing_canonical_form(schema["items"], fo)
fo.write("}")
elif schema_type == "map":
fo.write(f'{{"type":"{schema_type}","values":')
- _to_canonical_form(schema["values"], fo)
+ _to_parsing_canonical_form(schema["values"], fo)
fo.write("}")
elif schema_type == "enum":
@@ -716,7 +716,7 @@ def _to_canonical_form(schema, fo):
fo.write(",")
name = field["name"]
fo.write(f'{{"name":"{name}","type":')
- _to_canonical_form(field["type"], fo)
+ _to_parsing_canonical_form(field["type"], fo)
fo.write("}")
fo.write("]}")

MODIFY
fastavro/schema.py
fastavro/schema.py
@@ -16,7 +16,7 @@ parse_schema = _schema.parse_schema
fullname = _schema.fullname
expand_schema = _schema.expand_schema
load_schema_ordered = _schema.load_schema_ordered
-to_canonical_form = _schema.to_canonical_form
+to_parsing_canonical_form = _schema.to_parsing_canonical_form
__all__ = [
"UnknownType",
@@ -26,5 +26,5 @@ __all__ = [
"fullname",
"expand_schema",
"load_schema_ordered",
- "to_canonical_form",
+ "to_parsing_canonical_form",
]

MODIFY
tests/test_canonical_form.py
tests/test_canonical_form.py
import pytest
-from fastavro.schema import to_canonical_form
+from fastavro.schema import to_parsing_canonical_form
from fastavro._schema_common import PRIMITIVES
@@ -11,7 +11,7 @@ from fastavro._schema_common import PRIMITIVES
),
)
def test_primitive_conversion(original_schema, canonical_form):
- assert to_canonical_form(original_schema) == canonical_form
+ assert to_parsing_canonical_form(original_schema) == canonical_form
def test_fullname_conversion():
@@ -23,7 +23,7 @@ def test_fullname_conversion():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"namespace.test_fullname_conversion","type":"record","fields":[]}'
)
@@ -37,7 +37,7 @@ def test_fullname_conversion_empty_namespace():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_fullname_conversion_empty_namespace","type":"record","fields":[]}'
)
@@ -50,7 +50,7 @@ def test_fullname_conversion_no_namespace():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_fullname_conversion_no_namespace","type":"record","fields":[]}'
)
@@ -59,7 +59,7 @@ def test_remove_doc():
schema = {"name": "test_remove_doc", "type": "record", "fields": [], "doc": "doc"}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_remove_doc","type":"record","fields":[]}'
)
@@ -73,7 +73,7 @@ def test_remove_aliases():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_remove_aliases","type":"record","fields":[]}'
)
@@ -86,7 +86,7 @@ def test_record_field_order():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_record_field_order","type":"record","fields":[]}'
)
@@ -99,7 +99,7 @@ def test_enum_field_order():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_enum_field_order","type":"enum","symbols":["A","B"]}'
)
@@ -107,13 +107,13 @@ def test_enum_field_order():
def test_array_field_order():
schema = {"items": "int", "type": "array"}
- assert to_canonical_form(schema) == '{"type":"array","items":"int"}'
+ assert to_parsing_canonical_form(schema) == '{"type":"array","items":"int"}'
def test_map_field_order():
schema = {"values": "int", "type": "map"}
- assert to_canonical_form(schema) == '{"type":"map","values":"int"}'
+ assert to_parsing_canonical_form(schema) == '{"type":"map","values":"int"}'
def test_fixed_field_order():
@@ -124,7 +124,7 @@ def test_fixed_field_order():
}
assert (
- to_canonical_form(schema)
+ to_parsing_canonical_form(schema)
== '{"name":"test_fixed_field_order","type":"fixed","size":4}'
)
@@ -403,4 +403,4 @@ def test_fixed_field_order():
def test_random_cases(original_schema, canonical_form):
# All of these random test cases came from the test cases here:
# https://github.com/apache/avro/blob/0552c674637dd15b8751ed5181387cdbd81480d5/lang/py3/avro/tests/test_normalization.py
- assert to_canonical_form(original_schema) == canonical_form
+ assert to_parsing_canonical_form(original_schema) == canonical_form

change API function name