Skip to content

Commit

Permalink
add bound for class and function in parser field
Browse files Browse the repository at this point in the history
  • Loading branch information
voidZXL committed Dec 24, 2024
1 parent 076dec7 commit 5d7dd84
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion utype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
register_transformer = TypeTransformer.registry.register


VERSION = (0, 6, 2)
VERSION = (0, 6, 3)


def _get_version():
Expand Down
4 changes: 2 additions & 2 deletions utype/parser/cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def generate_fields(self):
**self.kwargs
)
except Exception as e:
raise exc.ConfigError(f'{self.name}: parse field [{repr(key)}] failed with error: {e}')
raise exc.ConfigError(f'{self.name}: generate field [{repr(key)}] failed with error: {e}')

fields.append(field)

Expand Down Expand Up @@ -195,7 +195,7 @@ def generate_fields(self):
**self.kwargs
)
except Exception as e:
raise exc.ConfigError(f'{self.name}: parse field [{repr(key)}] failed with error: {e}')
raise exc.ConfigError(f'{self.name}: generate field [{repr(key)}] failed with error: {e}')

fields.append(field)

Expand Down
8 changes: 7 additions & 1 deletion utype/parser/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def __init__(
max_contains: int = None,
min_contains: int = None,
unique_items: Union[bool, ConstraintMode] = None,
# todo?
# absence_error_message: str = None,
# parse_error_message: str = None,
):
super().__init__(locals())

Expand Down Expand Up @@ -445,6 +448,7 @@ def __init__(
final: bool = False,
positional_only: bool = False,
default=unprovided, # passed when using Annotated[]
bound=None,
**kwargs
):

Expand All @@ -458,6 +462,7 @@ def __init__(
self.property = field_property
self.final = final
self.name = name
self.bound = bound

all_aliases = [self.name]
_aliases = []
Expand Down Expand Up @@ -1326,7 +1331,8 @@ def generate(
final=final,
positional_only=positional_only,
default=_default,
bound=bound,
**kwargs
)
parser_field.setup(options=options)
parser_field.setup(options)
return parser_field
2 changes: 1 addition & 1 deletion utype/parser/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def generate_fields(self):
**self.kwargs
)
except Exception as e:
raise exc.ConfigError(f'{self.name}: parse field [{repr(name)}] failed with error: {e}')
raise exc.ConfigError(f'{self.name}: generate field [{repr(name)}] failed with error: {e}')

fields.append(
field
Expand Down
4 changes: 2 additions & 2 deletions utype/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DataClass(metaclass=LogicalMeta):
__parser__: ClassParser
__options__: Options

def __init__(self, **kwargs):
def __init__(self, *args, **kwargs):
pass

def __init_subclass__(cls, **kwargs):
Expand Down Expand Up @@ -235,7 +235,7 @@ def __coerce_property__(self, field: ParserField, context: RuntimeContext):
attr = field.property.fget(self) # get from the original getter
except Exception as e:
error_option = field.output_field.on_error if field.output_field else None
msg = f"@property: {repr(field.attname)} calculate failed with error: {e}"
msg = f"{self.__name__}: @property: {repr(field.attname)} calculate failed with error: {e}"
if error_option == context.options.THROW:
raise e.__class__(msg) from e
else:
Expand Down

0 comments on commit 5d7dd84

Please sign in to comment.