Skip to content

Commit 3adf266

Browse files
committed
Merge branch 'release/1.2.0.3' into main
2 parents 0eff8c4 + dbe4fc3 commit 3adf266

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Pyttman Changelog
22

3+
# V 1.2.0.3
4+
This is a hotfix release, fixing an issue with default values in
5+
TextEntityFields, causing a crash if it was combined with `as_list=True`, and
6+
`valid_strings`.
7+
8+
9+
### **🐛 Splatted bugs and corrected issues**
10+
* **Fixes [#68](https://github.com/dotchetter/Pyttman/issues/68)**
11+
12+
13+
314

415
# V 1.2.0.2
516

pyttman/core/entity_parsing/parsers.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,17 @@ def parse_message(self, message: MessageMixin,
133133

134134
if self.value:
135135
entity = self.value
136+
if entity.value == self.default:
137+
return
136138
if isinstance(entity.value, list):
137-
[message.content.remove(i) for i in entity.value]
139+
words_to_remove_from_message = entity.value
138140
entity.index_in_message += len(entity.value)
139141
elif isinstance(entity.value, str):
140-
message.content.remove(self.value)
142+
words_to_remove_from_message = [entity.value]
143+
144+
self._remove_words_from_message_unless_default(
145+
message,
146+
*words_to_remove_from_message)
141147
return
142148

143149
if self.truncates_message_in_parsing is False:
@@ -154,6 +160,23 @@ def parse_message(self, message: MessageMixin,
154160
else:
155161
self.reset()
156162

163+
def _remove_words_from_message_unless_default(
164+
self,
165+
message,
166+
*words_to_remove_from_message) -> None:
167+
"""
168+
Removes elements from message.content, if they're present
169+
in the message, unless a word or other object happens to
170+
equal the 'self.default' property on the instance.
171+
"""
172+
for word in words_to_remove_from_message:
173+
if word == self.default:
174+
continue
175+
try:
176+
message.content.remove(word)
177+
except ValueError:
178+
continue
179+
157180
def _validate_message_with_affixes(self,
158181
affixes: tuple[str],
159182
message: MessageMixin,

pyttman/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
__version__ = "1.2.0.2a"
2+
__version__ = "1.2.0.3"

tests/core/entity_parsing/test_entity_fields/test_entity_parsing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,22 @@ class IntentClass(ImplementedTestIntent):
345345

346346
is_break = BoolEntityField(message_contains=("break",))
347347
is_workshift = BoolEntityField(message_contains=("workshift",))
348+
349+
350+
class PyttmanIntentInternalTestTextEntityDefault(
351+
PyttmanInternalTestBaseCase
352+
):
353+
mock_message = Message("I would like the blue cheese, please.")
354+
process_message = True
355+
expected_entities = {
356+
"cheese_type": ["blue"],
357+
}
358+
359+
class IntentClass(ImplementedTestIntent):
360+
"""
361+
Tests that the 'workshift' from 'lead' is not removed
362+
from parsing, and can be used as entities.
363+
"""
364+
cheese_type = StringEntityField(valid_strings=("blue", "yellow"),
365+
default="blue",
366+
as_list=True)

0 commit comments

Comments
 (0)