File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 22
33from io import BytesIO
44import json
5+ from typing import Union
56
67import fastavro
78
@@ -12,15 +13,19 @@ class AvroSchema(Schema):
1213 """Implementation of the `Schema` protocol for Avro schemas.
1314
1415 Arguments:
15- string : the stringified schema definition
16+ definition : the schema, either as a parsed dict or a string
1617 return_record_name: if true, when reading a union of records,
1718 the result will be a tuple where the first value is the
1819 name of the record and the second value is the record
1920 itself
2021 """
2122
22- def __init__ (self , string : str , return_record_name : bool = False ):
23- self ._dict = json .loads (string )
23+ def __init__ (self , definition : Union [str , dict ],
24+ return_record_name : bool = False ):
25+ if isinstance (definition , str ):
26+ self ._dict = json .loads (definition )
27+ else :
28+ self ._dict = definition
2429 self ._parsed = fastavro .parse_schema (self ._dict )
2530 self .return_record_name = return_record_name
2631
You can’t perform that action at this time.
0 commit comments