Replies: 6 comments
-
Related discussion here, since being able to add arbitrary annotations might solve one piece of this fable-compiler/Fable.Python#48 |
Beta Was this translation helpful? Give feedback.
-
Since it would be difficult to get things like discriminated unions and string enums working with pedantic, I'm going a different route for now of generating the json schema using a myriad plugin. |
Beta Was this translation helpful? Give feedback.
-
I think this is a great idea that we should explore. I don't have the capacity right now, but I'll keep it in mind. |
Beta Was this translation helpful? Give feedback.
-
@joprice This should now be fixed with #4199. E.g: [<Erase>]
type Field<'T> = 'T
[<Import("Field", "pydantic")>]
let Field (description: string): Field<'T> = nativeOnly
[<Import("BaseModel", "pydantic")>]
type BaseModel () = class end
// Test PythonClass attribute with attributes style
[<Py.ClassAttributes(style="attributes", init=false)>]
type AttributesUser() =
inherit BaseModel()
member val Name: Field<string> = Field("Name") with get, set
member val Age: int = 10 with get, set
member val Email: string option = None with get, set Now becomes: class AttributesUser(BaseModel):
Age: int32 = int32(10)
Email: str | None = None
Name: str = Field("Name") Still need some work on the |
Beta Was this translation helpful? Give feedback.
-
This next PR is also relevant to add Python decorators to classes: #4200 |
Beta Was this translation helpful? Give feedback.
-
Some more improvements here: #4207 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there any pattern for generating a type that is annotated in a way that is usable by pydantic. Some libraries rely on it for generating a schema by calling
model_json_schema
on the type. Pydantic defines its own dataclasses, but the docs say that it has some compatibility with stdlib dataclasses:https://docs.pydantic.dev/latest/concepts/dataclasses/#usage-of-stdlib-dataclasses-with-basemodel
I've tried a few combinations to generate a class that it likes, but haven't yet been able to get it to recognize its properties.
Beta Was this translation helpful? Give feedback.
All reactions