Skip to content

Commit 5fb3780

Browse files
committed
Change type() to isinstance() to check object types
1 parent c1d2887 commit 5fb3780

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

nemoguardrails/actions/llm/generation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def _extract_user_message_example(self, flow: Flow) -> None:
156156
# The SpecOp.spec type is Union[Spec, dict]. Convert Dict to Spec if it's provided
157157
match_spec: Spec = (
158158
spec_op.spec
159-
if type(spec_op.spec) == Spec
159+
if isinstance(spec_op.spec, Spec)
160160
else Spec(**cast(Dict, spec_op.spec))
161161
)
162162

@@ -179,7 +179,7 @@ def _extract_user_message_example(self, flow: Flow) -> None:
179179
# which isn't in the Spec definition
180180
await_spec_dict: Dict[str, Any] = (
181181
asdict(spec_op.spec)
182-
if type(spec_op.spec) == Spec
182+
if isinstance(spec_op.spec, Spec)
183183
else cast(Dict, spec_op.spec)
184184
)
185185

@@ -213,15 +213,15 @@ def _extract_bot_message_example(self, flow: Flow):
213213

214214
el = flow.elements[1]
215215

216-
if type(el) != SpecOp:
216+
if not isinstance(el, SpecOp):
217217
return
218218

219219
spec_op: SpecOp = cast(SpecOp, el)
220220
spec: Dict[str, Any] = (
221221
asdict(
222222
spec_op.spec
223-
) # TODO! Refactor thiss function as it's duplicated in many places
224-
if type(spec_op.spec) == Spec
223+
) # TODO! Refactor this function as it's duplicated in many places
224+
if isinstance(spec_op.spec, Spec)
225225
else cast(Dict, spec_op.spec)
226226
)
227227

@@ -241,7 +241,7 @@ def _process_flows(self):
241241
"""Process the provided flows to extract the user utterance examples."""
242242
# Flows can be either Flow or Dict. Convert them all to Flow for following code
243243
flows: List[Flow] = [
244-
cast(Flow, flow) if type(flow) == Flow else Flow(**cast(Dict, flow))
244+
cast(Flow, flow) if isinstance(flow, Flow) else Flow(**cast(Dict, flow))
245245
for flow in self.config.flows
246246
]
247247

nemoguardrails/actions/v2_x/generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async def _collect_user_intent_and_examples(
217217
heads = find_all_active_event_matchers(state)
218218
for head in heads:
219219
el = get_element_from_head(state, head)
220-
element = el if type(el) == SpecOp else SpecOp(**cast(Dict, el))
220+
element = el if isinstance(el, SpecOp) else SpecOp(**cast(Dict, el))
221221
flow_state = state.flow_states[head.flow_state_uid]
222222
event = get_event_from_element(state, flow_state, element)
223223
if (

0 commit comments

Comments
 (0)