Skip to content

Commit f43e73e

Browse files
committed
Final cleanups
1 parent 8a5577e commit f43e73e

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

nemoguardrails/colang/runtime.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,34 @@ def __init__(self, config: RailsConfig, verbose: bool = False):
3232
self.verbose = verbose
3333

3434
# Register the actions with the dispatcher.
35+
paths = config.imported_paths
36+
import_paths = list(paths.values()) if paths else None
3537
self.action_dispatcher = ActionDispatcher(
3638
config_path=config.config_path,
37-
import_paths=list(
38-
config.imported_paths.values() if config.imported_paths else []
39-
),
39+
import_paths=import_paths,
4040
)
4141

4242
if hasattr(self, "_run_output_rails_in_parallel_streaming"):
4343
self.action_dispatcher.register_action(
44-
getattr(self, "_run_output_rails_in_parallel_streaming"),
44+
self._run_output_rails_in_parallel_streaming, # type: ignore[attr-defined]
4545
name="run_output_rails_in_parallel_streaming",
4646
)
4747

4848
if hasattr(self, "_run_flows_in_parallel"):
4949
self.action_dispatcher.register_action(
50-
getattr(self, "_run_flows_in_parallel"), name="run_flows_in_parallel"
50+
self._run_flows_in_parallel, # type: ignore[attr-defined]
51+
name="run_flows_in_parallel",
5152
)
5253

5354
if hasattr(self, "_run_input_rails_in_parallel"):
5455
self.action_dispatcher.register_action(
55-
getattr(self, "_run_input_rails_in_parallel"),
56+
self._run_input_rails_in_parallel, # type: ignore[attr-defined]
5657
name="run_input_rails_in_parallel",
5758
)
5859

5960
if hasattr(self, "_run_output_rails_in_parallel"):
6061
self.action_dispatcher.register_action(
61-
getattr(self, "_run_output_rails_in_parallel"),
62+
self._run_output_rails_in_parallel, # type: ignore[attr-defined]
6263
name="run_output_rails_in_parallel",
6364
)
6465

nemoguardrails/colang/v1_0/lang/comd_parser.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,24 @@ def parse_md_file(file_name, content=None):
362362
continue
363363

364364
# Make sure we have the type of the symbol in the name of the symbol
365-
if sym is not None:
366-
sym = _get_typed_symbol_name(sym, symbol_type)
365+
if not sym or not isinstance(sym, str):
366+
raise ValueError(f"sym must be a non-empty string, found {sym}")
367+
368+
sym = _get_typed_symbol_name(sym, symbol_type)
367369

368-
# For objects, we translate the "string" type to "kb:Object:prop|partial"
369-
param_type = _get_param_type(parts[1])
370-
if symbol_type == "object" and param_type in ["string", "text"]:
371-
object_name = split_max(sym, ":", 1)[1]
372-
param_type = f"kb:{object_name}:{parts[0]}|partial"
370+
# For objects, we translate the "string" type to "kb:Object:prop|partial"
371+
param_type = _get_param_type(parts[1])
372+
if symbol_type == "object" and param_type in ["string", "text"]:
373+
object_name = split_max(sym, ":", 1)[1]
374+
param_type = f"kb:{object_name}:{parts[0]}|partial"
373375

374-
# TODO: figure out a cleaner way to deal with this
375-
# For the "type:time" type, we transform it into "lookup:time"
376-
if param_type == "type:time":
377-
param_type = "lookup:time"
376+
# TODO: figure out a cleaner way to deal with this
377+
# For the "type:time" type, we transform it into "lookup:time"
378+
if param_type == "type:time":
379+
param_type = "lookup:time"
378380

379-
result["mappings"].append((f"{sym}:{parts[0]}", param_type))
380-
symbol_params.append(parts[0])
381+
result["mappings"].append((f"{sym}:{parts[0]}", param_type))
382+
symbol_params.append(parts[0])
381383

382384
elif line.startswith("-") or line.startswith("*"):
383385
if sym is None:

0 commit comments

Comments
 (0)