Skip to content

Commit 35c06fe

Browse files
committed
better error handling
1 parent 0df2a3a commit 35c06fe

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/py_avro_schema/_schemas.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,10 @@ def __init__(self, py_type: Type, namespace: Optional[str] = None, options: Opti
387387
"""An Avro schema for Python ``typing.Final``"""
388388
super().__init__(py_type, namespace, options)
389389
py_type = _type_from_annotated(py_type)
390-
real_type = get_args(py_type)[0]
390+
try:
391+
real_type = get_args(py_type)[0]
392+
except IndexError:
393+
raise TypeError("Can't generate Avro schema from Python typing.Final without a type parameter")
391394
self.real_schema = _schema_obj(real_type, namespace=namespace, options=options)
392395

393396
def data(self, names: NamesType) -> JSONType:
@@ -398,7 +401,7 @@ def data(self, names: NamesType) -> JSONType:
398401
def handles_type(cls, py_type: Type) -> bool:
399402
"""Whether this schema class can represent a given Python class"""
400403
py_type = _type_from_annotated(py_type)
401-
return get_origin(py_type) is Final
404+
return get_origin(py_type) is Final or py_type is Final
402405

403406

404407
@register_schema

0 commit comments

Comments
 (0)