Skip to content

Commit

Permalink
work to upgrade to latest pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
ademariag committed Mar 29, 2024
1 parent b34e780 commit e59a660
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 149 deletions.
17 changes: 7 additions & 10 deletions kadet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

import hashlib
import json
from typing import ClassVar

from typing import Any, Annotated
import yaml
from box import Box, BoxList
from pydantic import BaseModel as PydanticBaseModel
from pydantic import Extra
from pydantic import BaseModel as PydanticBaseModel, Field
from typeguard import check_type

ABORT_EXCEPTION_TYPE = ValueError
Expand Down Expand Up @@ -110,7 +108,7 @@ def need(self, key, msg="key and value needed", istype=None):
if key not in self.kwargs:
raise ABORT_EXCEPTION_TYPE(err_msg) # XXX in Kapitan this is CompileError
elif istype is not None:
check_type(key, self.kwargs[key], istype)
check_type(self.kwargs[key], istype)

def optional(self, key, default=None, istype=None):
"""Set self.kwargs key as optional.
Expand All @@ -119,13 +117,13 @@ def optional(self, key, default=None, istype=None):
match type passed in istype.
"""
if key in self.kwargs and istype is not None:
check_type(key, self.kwargs[key], istype)
check_type(self.kwargs[key], istype)

if key not in self.kwargs:
if default is None:
self.kwargs[key] = default
elif istype is not None:
check_type(key, default, istype)
check_type(default, istype)
self.kwargs[key] = default

def new(self):
Expand Down Expand Up @@ -195,11 +193,10 @@ def sha256(self):


class BaseModel(PydanticBaseModel):
root: ClassVar # hide root from repr
root: Annotated[Dict, Field(repr=False)] = Dict()

def __init__(self, **data):
super().__init__(**data)
self.root = Dict() # initialise empty root

if hasattr(self, "new"):
assert callable(self.new)
Expand Down Expand Up @@ -258,4 +255,4 @@ class Config:
arbitrary_types_allowed = True # allow all types e.g. BaseObj
copy_on_model_validation = False # performance?
underscore_attrs_are_private = True
extra = Extra.allow
extra = 'allow'
Loading

0 comments on commit e59a660

Please sign in to comment.