Skip to content

Commit d826bc6

Browse files
committed
renamed 'pre_processor' to 'post_processor' since it offersa a way to process an entity value after initial processing
1 parent 4a66a8e commit d826bc6

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pyttman/core/entity_parsing/fields.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EntityFieldBase(EntityFieldValueParser, ABC):
3939
patterns in text. You can provide a custom Identifier class
4040
to further increase the granularity of the value you're looking for.
4141
"""
42-
pre_processor = None
42+
post_processor = None
4343
"""
4444
Pre-processor is a callable which is called before the
4545
value is converted to the type_cls of the EntityField.
@@ -50,7 +50,7 @@ class EntityFieldBase(EntityFieldValueParser, ABC):
5050
def __init__(self,
5151
identifier: Type[Identifier] | None = None,
5252
default: Any = None,
53-
pre_processor: callable = None,
53+
post_processor: callable = None,
5454
**kwargs):
5555
"""
5656
:param as_list: If set to True combined with providing 'valid_strings',
@@ -67,7 +67,7 @@ def __init__(self,
6767
You can read more about Identifier classes in the Pyttman
6868
documentation.
6969
"""
70-
self.pre_processor = pre_processor
70+
self.post_processor = post_processor
7171
if self.type_cls is None or inspect.isclass(self.type_cls) is False:
7272
raise InvalidPyttmanObjectException("All EntityField classes "
7373
"must define a 'type_cls', "
@@ -113,11 +113,11 @@ def convert_value(self, value: Any) -> Any:
113113
to_type=self.type_cls) from e
114114

115115
try:
116-
if self.pre_processor is not None and callable(self.pre_processor):
117-
converted_value = self.pre_processor(converted_value)
116+
if self.post_processor is not None and callable(self.post_processor):
117+
converted_value = self.post_processor(converted_value)
118118
except Exception as e:
119-
value_err = ValueError("The pre_processor callable '"
120-
f"'{self.pre_processor}' failed: {e}")
119+
value_err = ValueError("The post_processor callable '"
120+
f"'{self.post_processor}' failed: {e}")
121121
raise TypeConversionFailed(from_type=type(value),
122122
to_type=self.type_cls) from value_err
123123
return converted_value

tests/core/entity_parsing/test_entity_fields/test_entity_parsing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ class PyttmanInternalTestEntityPreProcessor(
422422

423423
class IntentClass(ImplementedTestIntent):
424424
"""
425-
Tests that the 'pre_processor' callable is executed and
425+
Tests that the 'post_processor' callable is executed and
426426
can process the return value before it's spat out.
427427
"""
428428
beverage = StringEntityField(valid_strings=("tea", "coffee"),
429-
pre_processor=lambda x: x.capitalize())
429+
post_processor=lambda x: x.capitalize())
430430

0 commit comments

Comments
 (0)