dbt-labs / hologram

A library for automatically generating Draft 7 JSON Schemas from Python dataclasses
MIT License
9 stars 13 forks source link

(#34) Add support for Python 3.9 #37

Closed drewbanin closed 3 years ago

drewbanin commented 3 years ago

Fixes #34

This PR updates Hologram's type inference code to be compatible with changes in Python 3.9. Previously, Optional types were treated as Union[_type_, None]. In Python 3.9, the Optional type is preserved directly. This PR replaces logic that checks for Union types with corresponding logic that checks for Optional types.

I smoke tested this locally, but would be great to run the dbt integration tests on Py39 while pointing to this hologram branch

gshank commented 3 years ago

This commit regresses the change in hologram/init.py to stop using 'best_match', which caused the test failures. This change should be undone:

-        error = next(iter(validator.iter_errors(data)), None)
+        error = jsonschema.exceptions.best_match(validator.iter_errors(data))
drewbanin commented 3 years ago

ooh - thanks @gshank! I was confused about the test failure for sure. I did something silly when making this branch - thanks for the quick pointer :D

gshank commented 3 years ago

This looks good for hologram. I've opened issue #2822 to create tox.ini targets for dbt and test with it.

drewbanin commented 3 years ago

hey @Sherm4nLC - this error is caused by some changes in Python v3.9 (newly released). That error is in fact fixed by this PR! If you're hitting this snag still, you can try running dbt with Python v3.8. We'll have this code change live in the next release of dbt, which should get Python v3.9 working correctly