Skip to content

Commit 9bc839f

Browse files
authored
refactor: Add default context values as ModelParsingContext for _model classes inheriting from FormatString (#191)
Signed-off-by: Brian Axelson <[email protected]>
1 parent 4073d2d commit 9bc839f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/openjd/model/v2023_09/_model.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class ValueReferenceConstants(Enum):
183183
class JobTemplateName(FormatString):
184184
_min_length = 1
185185

186+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
187+
return super().__new__(cls, value, context=context)
188+
186189

187190
JobName = Annotated[
188191
str,
@@ -225,12 +228,18 @@ class CommandString(FormatString):
225228
# All unicode except the [Cc] (control characters) category
226229
_regex = f"(?-m:^[^{_Cc_characters}]+\\Z)"
227230

231+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
232+
return super().__new__(cls, value, context=context)
233+
228234

229235
class ArgString(FormatString):
230236
# All unicode except the [Cc] (control characters) category
231237
# Allow CR, LF, and TAB.
232238
_regex = f"(?-m:^[^{_Cc_characters}]*\\Z)"
233239

240+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
241+
return super().__new__(cls, value, context=context)
242+
234243

235244
class CancelationMode(str, Enum):
236245
NOTIFY_THEN_TERMINATE = "NOTIFY_THEN_TERMINATE"
@@ -363,6 +372,9 @@ class EmbeddedFileTypes(str, Enum):
363372
class DataString(FormatString):
364373
_min_length = 1
365374

375+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
376+
return super().__new__(cls, value, context=context)
377+
366378

367379
class EmbeddedFileText(OpenJDModel_v2023_09):
368380
"""A plain text file embedded directly into the Job Template.
@@ -485,7 +497,8 @@ class TaskParameterStringValue(FormatString):
485497
# as a TaskParameterStringValueAsJob type after the template
486498
# has been instantiated in to a Job, and this format string
487499
# has been evaluated.
488-
pass
500+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
501+
return super().__new__(cls, value, context=context)
489502

490503

491504
class TaskParameterType(str, Enum):
@@ -499,6 +512,9 @@ class TaskParameterType(str, Enum):
499512
class RangeString(FormatString):
500513
_min_length = 1
501514

515+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
516+
return super().__new__(cls, value, context=context)
517+
502518

503519
# Note: Ordering within the Unions is important. Pydantic will try to match in
504520
# the order given.
@@ -994,6 +1010,9 @@ def _validate_combination(self) -> Self:
9941010
class EnvironmentVariableValueString(FormatString):
9951011
_max_length = 2048
9961012

1013+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
1014+
return super().__new__(cls, value, context=context)
1015+
9971016

9981017
EnvironmentVariableObject = dict[EnvironmentVariableNameString, EnvironmentVariableValueString]
9991018

@@ -2011,17 +2030,26 @@ class AmountCapabilityName(FormatString):
20112030
_min_length = 1
20122031
_max_length = 100
20132032

2033+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
2034+
return super().__new__(cls, value, context=context)
2035+
20142036

20152037
class AttributeCapabilityName(FormatString):
20162038
"""The name of an attrubute capability."""
20172039

20182040
_min_length = 1
20192041
_max_length = 100
20202042

2043+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
2044+
return super().__new__(cls, value, context=context)
2045+
20212046

20222047
class AttributeCapabilityValue(FormatString):
20232048
_min_length = 1
20242049

2050+
def __new__(cls, value: str, *, context: ModelParsingContextInterface = ModelParsingContext()):
2051+
return super().__new__(cls, value, context=context)
2052+
20252053

20262054
AttributeCapabilityList = Annotated[
20272055
list[AttributeCapabilityValue], Field(min_length=1, max_length=50)

0 commit comments

Comments
 (0)