jpmorganchase / py-avro-schema

Generate Apache Avro schemas for Python types including standard library data-classes and Pydantic data models.
https://py-avro-schema.readthedocs.io/
Apache License 2.0
37 stars 6 forks source link

feat(pydantic): allow pydantic model instances as defaults (#64) #65

Closed dada-engineer closed 8 months ago

dada-engineer commented 8 months ago

This allows pydantic BaseModels as default values.

Fixes #64

dada-engineer commented 8 months ago

linting fails because black and flake8 have a different opinion on how

class PyType(str):
    ...

should be formatted.

black now wants to do:

class PyType(str): ...

But flake8 then complains that there are multiple statements on one line.

faph commented 8 months ago

So this flake8 vs black conflict. Is there a way that we can configure either of the tools to handle this OK?

dada-engineer commented 8 months ago

So this flake8 vs black conflict. Is there a way that we can configure either of the tools to handle this OK?

I guess this comment makes sense: https://github.com/psf/black/issues/4213#issuecomment-1928364118

TLDR; deactivate flake8 rule for stuff that is handled by formatter.

faph commented 8 months ago

Got you, so that should be a change in .flake8 file?

dada-engineer commented 8 months ago

Looks like it, should I add this here?

dada-engineer commented 8 months ago

Had some issue with mypy as well, fixed in same commit.

faph commented 8 months ago

Love it!

Are we good to merge?

dada-engineer commented 8 months ago

I am okay with it, but since I removed it lists of pydantic objects will not yet work. I'll open a new issue for this or a second PR later.

faph commented 8 months ago

Understood. Many thanks for this contribution.

koenlek commented 1 month ago

Thanks for making this fix! Unfortunately, I'm stuck on py-avro-schema v2 (and upgrading is going to be very hard I'm afraid). Any suggestions on how I could try and patch v2 or work around this issue?

I tried patching the make_default logic into v2, but it doesn't seem to work unfortunately...

Any hints would be highly appreciated 🙏

koenlek commented 1 month ago

NVM. Gotten it to work and posted it for others here: https://github.com/jpmorganchase/py-avro-schema/issues/64#issuecomment-2388957280