liminal-orm 2.0.2__py3-none-any.whl → 2.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import inspect
2
1
  from datetime import datetime
3
2
  from functools import partial, wraps
4
3
  from typing import TYPE_CHECKING, Any, Callable
@@ -101,24 +100,33 @@ class BenchlingValidatorReport(BaseModel):
101
100
  )
102
101
 
103
102
 
104
- def _liminal_decorator(
105
- func: Callable[[type["BenchlingBaseModel"]], BenchlingValidatorReport | None],
106
- validator_level: ValidationSeverity,
107
- validator_name: str | None,
103
+ def liminal_validator(
104
+ func: Callable[["BenchlingBaseModel"], BenchlingValidatorReport | None]
105
+ | None = None,
106
+ *,
107
+ validator_level: ValidationSeverity = ValidationSeverity.LOW,
108
+ validator_name: str | None = None,
108
109
  ) -> Callable:
109
- """Core decorator logic for liminal_validator."""
110
- sig = inspect.signature(func)
111
- params = list(sig.parameters.values())
112
- if not params or params[0].name != "self" or len(params) > 1:
113
- raise TypeError(
114
- "Validator must be defined in a schema class, where the only argument to this validator must be 'self'."
115
- )
110
+ """A decorator for a function that validates a Benchling entity, defined on a schema class.
111
+ Can be used with or without parameters. Wraps around any exceptions raised by the validator function,
112
+ and returns a BenchlingValidatorReport.
116
113
 
117
- if validator_name is None:
118
- validator_name = pascalize(func.__name__)
114
+ Parameters
115
+ ----------
116
+ validator_level: ValidationSeverity
117
+ The severity level of the validation report. Defaults to ValidationSeverity.LOW.
118
+ validator_name: str | None
119
+ The name of the validator. Defaults to the PascalCase version of the function name.
120
+ """
121
+ if func is None:
122
+ return partial(
123
+ liminal_validator,
124
+ validator_level=validator_level,
125
+ validator_name=validator_name,
126
+ )
119
127
 
120
128
  @wraps(func)
121
- def wrapper(self: type["BenchlingBaseModel"]) -> BenchlingValidatorReport:
129
+ def wrapper(self: "BenchlingBaseModel") -> BenchlingValidatorReport:
122
130
  """Wrapper that runs the validator function and returns a BenchlingValidatorReport."""
123
131
  try:
124
132
  ret_val = func(self)
@@ -129,36 +137,15 @@ def _liminal_decorator(
129
137
  valid=False,
130
138
  level=validator_level,
131
139
  entity=self,
132
- validator_name=validator_name,
140
+ validator_name=validator_name or pascalize(func.__name__),
133
141
  message=str(e),
134
142
  )
135
143
  return BenchlingValidatorReport.create_validation_report(
136
144
  valid=True,
137
145
  level=validator_level,
138
146
  entity=self,
139
- validator_name=validator_name,
147
+ validator_name=validator_name or pascalize(func.__name__),
140
148
  )
141
149
 
142
150
  setattr(wrapper, "_is_liminal_validator", True)
143
151
  return wrapper
144
-
145
-
146
- def liminal_validator(
147
- validator_level: ValidationSeverity = ValidationSeverity.LOW,
148
- validator_name: str | None = None,
149
- ) -> Callable:
150
- """A decorator for a function that validates a Benchling entity, defined on a schema class.
151
- Wraps around any exceptions raised by the validator function, and returns a BenchlingValidatorReport.
152
-
153
- Parameters
154
- ----------
155
- validator_level: ValidationSeverity
156
- The severity level of the validation report. Defaults to ValidationSeverity.LOW.
157
- validator_name: str | None =
158
- The name of the validator. Defaults to the PascalCase version of the function name.
159
- """
160
- return partial(
161
- _liminal_decorator,
162
- validator_level=validator_level,
163
- validator_name=validator_name,
164
- )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: liminal-orm
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: An ORM and toolkit that builds on top of Benchling's platform to keep your schemas and downstream code dependencies in sync.
5
5
  Home-page: https://github.com/dynotx/liminal-orm
6
6
  Author: DynoTx Open Source
@@ -59,10 +59,10 @@ liminal/tests/from benchling_sdk.py,sha256=CjRUHFB3iaa4rUPLGOqDiBq5EPKldm-Fd8aQQ
59
59
  liminal/tests/test_dropdown_compare.py,sha256=yHB0ovQlBLRu8-qYkqIPd8VtYEOmOft_93FQM86g_z8,8198
60
60
  liminal/tests/test_entity_schema_compare.py,sha256=-26Bu5eYIuHRswB5kYjGDo5Wed5LUWjm1e6IRI1Q-lE,18952
61
61
  liminal/utils.py,sha256=radRtRsZmCiNblMvxOX1DH0rcO5TR09kFlp6OONIPBU,2951
62
- liminal/validation/__init__.py,sha256=aMxO1vcZ_1Ay1Br0BCEEc09xge8-g5TL1sJ0KHbtRM8,5684
62
+ liminal/validation/__init__.py,sha256=TVaHrSF3GnSd4mbZrPn8TBHscGWkAPKAUUPq7-symC8,5275
63
63
  liminal/validation/validation_severity.py,sha256=ib03PTZCQHcbBDc01v4gJF53YtA-ANY6QSFnhTV-FbU,259
64
- liminal_orm-2.0.2.dist-info/LICENSE.md,sha256=oVA877F_D1AV44dpjsv4f-4k690uNGApX1EtzOo3T8U,11353
65
- liminal_orm-2.0.2.dist-info/METADATA,sha256=xOqcfpE7GSkUtmzLq_aNi8xGC74QEmKgK1Ki50przG4,11032
66
- liminal_orm-2.0.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
67
- liminal_orm-2.0.2.dist-info/entry_points.txt,sha256=atIrU63rrzH81dWC2sjUbFLlc5FWMmYRdMxXEWexIZA,47
68
- liminal_orm-2.0.2.dist-info/RECORD,,
64
+ liminal_orm-2.0.3.dist-info/LICENSE.md,sha256=oVA877F_D1AV44dpjsv4f-4k690uNGApX1EtzOo3T8U,11353
65
+ liminal_orm-2.0.3.dist-info/METADATA,sha256=Gq7H7QpXrTZouxJAvjnHQA_iCL95i8FcDuAUWLJKvMk,11032
66
+ liminal_orm-2.0.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
67
+ liminal_orm-2.0.3.dist-info/entry_points.txt,sha256=atIrU63rrzH81dWC2sjUbFLlc5FWMmYRdMxXEWexIZA,47
68
+ liminal_orm-2.0.3.dist-info/RECORD,,