Skip to content

Commit

Permalink
refactor traitlet import
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed Dec 18, 2024
1 parent 8cb35ff commit 4faf955
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions jhub_apps/config_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from traitlets import Int, Unicode, Union, List, Callable, Integer
import textwrap
import typing as t
from pydantic import BaseModel, ValidationError
from traitlets import Int, Unicode, Union, List, Callable, Integer, TraitType, TraitError
from traitlets.config import SingletonConfigurable, Enum

from jhub_apps.service.models import StartupApp

import textwrap
import typing as t
from pydantic import BaseModel, ValidationError
from traitlets import TraitType
import traitlets

class PydanticModelTrait(TraitType):
"""A trait type for validating Pydantic models.
Expand Down Expand Up @@ -56,10 +54,10 @@ def validate(self, obj: t.Any, value: t.Any) -> BaseModel:
return self.model_class(**value)
except ValidationError as e:
# Convert Pydantic validation error to TraitError
raise traitlets.TraitError(f'Could not parse input as a valid {self.model_class.__name__} Pydantic model:\n'
raise TraitError(f'Could not parse input as a valid {self.model_class.__name__} Pydantic model:\n'
f'{textwrap.indent(str(e), prefix=" ")}')

raise traitlets.TraitError(f'Input must be a valid {self.model_class.__name__} Pydantic model or dict object, but got {value}.')
raise TraitError(f'Input must be a valid {self.model_class.__name__} Pydantic model or dict object, but got {value}.')


class JAppsConfig(SingletonConfigurable):
Expand Down

0 comments on commit 4faf955

Please sign in to comment.