Skip to content

Instantly share code, notes, and snippets.

@kervel
Created December 22, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kervel/5591569829abf640dea839204398efcd to your computer and use it in GitHub Desktop.
Save kervel/5591569829abf640dea839204398efcd to your computer and use it in GitHub Desktop.
result polymorphism data
from __future__ import annotations
from datetime import datetime, date
from enum import Enum
from typing import List, Dict, Optional, Any, Union
from pydantic import BaseModel as BaseModel, Field
from linkml_runtime.linkml_model import Decimal
metamodel_version = "None"
version = "None"
class WeakRefShimBaseModel(BaseModel):
__slots__ = '__weakref__'
class ConfiguredBaseModel(WeakRefShimBaseModel,
validate_assignment = True,
validate_all = True,
underscore_attrs_are_private = True,
extra = 'forbid',
arbitrary_types_allowed = True):
pass
class NamedThing(ConfiguredBaseModel):
id: str = Field(None)
full_name: Optional[str] = Field(None)
type: Optional[str] = Field("http://example.org/test-schema/:NamedThing", const=True)
class Person(NamedThing):
height: Optional[int] = Field(None)
id: str = Field(None)
full_name: Optional[str] = Field(None)
type: Optional[str] = Field("http://example.org/test-schema/:Person", const=True)
class Organisation(NamedThing):
number_of_employees: Optional[int] = Field(None)
id: str = Field(None)
full_name: Optional[str] = Field(None)
type: Optional[str] = Field("http://example.org/test-schema/:Organisation", const=True)
class Container(ConfiguredBaseModel):
things: Optional[Dict[str, str]] = Field(default_factory=list)
# Update forward refs
# see https://pydantic-docs.helpmanual.io/usage/postponed_annotations/
NamedThing.update_forward_refs()
Person.update_forward_refs()
Organisation.update_forward_refs()
Container.update_forward_refs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment