import datetime import decimal import dateutil from apistar import typesystem class Datetime(datetime.datetime): native_type = datetime.datetime def __new__(cls, *args, **kwargs) -> datetime: if args and isinstance(args[0], cls.native_type): return args[0] if args and isinstance(args[0], str): try: return dateutil.parser.parse(args[0]) except ValueError: raise typesystem.TypeSystemError(cls=cls, code='type') from None return cls.native_type(*args, **kwargs) class Decimal(typesystem._NumericType, decimal.Decimal): native_type = decimal.Decimal