Skip to content

Commit

Permalink
Support annotated dates
Browse files Browse the repository at this point in the history
  • Loading branch information
faph committed Nov 17, 2023
1 parent 681e521 commit 0294169
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/py_avro_schema/_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,7 @@ class DateSchema(Schema):
@classmethod
def handles_type(cls, py_type: Type) -> bool:
"""Whether this schema class can represent a given Python class"""
return (
inspect.isclass(py_type)
and issubclass(py_type, datetime.date)
and not issubclass(py_type, datetime.datetime)
)
return _is_class(py_type, datetime.date) and not _is_class(py_type, datetime.datetime)

def data(self, names: NamesType) -> JSONObj:
"""Return the schema data"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_logicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ def test_date():
assert_schema(py_type, expected)


def test_date_annotated():
py_type = Annotated[datetime.date, ...]
expected = {
"type": "int",
"logicalType": "date",
}
assert_schema(py_type, expected)


def test_time():
py_type = datetime.time
expected = {
Expand Down

0 comments on commit 0294169

Please sign in to comment.