-
Notifications
You must be signed in to change notification settings - Fork 548
chore(types): Type-clean tracing (10 errors) #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments only on my side.
if hasattr(action, "error") and action.error | ||
else None | ||
), | ||
# TODO: There is no error field in ExecutedAction. The fields below are defined on BaseSpan but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure here - maybe @Pouyanpi can provide some feedback quicker than me.
id=interaction_output.id, | ||
activated_rails=generation_log.activated_rails, | ||
events=generation_log.internal_events, | ||
events=generation_log.internal_events or [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why Pyright is complaining about this as events is default factory of List
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this @tgasser-nv 👍🏻
Description (generated in Cursor)
Type Fixes Summary for
nemoguardrails/tracing/
DirectoryOverview
Fixed type errors across 3 files in the tracing module based on commit
e939b0a
. All changes maintain backward compatibility and preserve existing functionality.Fixes by Risk Level (Most Risky First)
🔴 HIGH RISK -
tracer.py
(lines 69-71)Original Error:
Argument of type "GenerationLog | None" cannot be assigned to parameter "generation_log" of type "GenerationLog"
Fix: Added explicit null check with Exception
Downside: Changes runtime behavior - now throws exception instead of potentially passing None to downstream function. However, this makes the error explicit rather than allowing undefined behavior.
🟡 MEDIUM RISK -
span_extractors.py
(lines 222-231)Original Errors: Multiple
Cannot access attribute "error" for class "ExecutedAction"
errorsFix: Replaced dynamic error attribute access with explicit None values and added TODO comment
Downside: Loss of potential future error information - if ExecutedAction gains an error field in the future, this code won't capture it. However, the TODO comment documents the intentional design decision.
🟢 LOW RISK -
span_extractors.py
(lines 62, 168, 170)Original Errors:
Type "List[SpanLegacy]" is not assignable to return type "List[SpanOpentelemetry | SpanLegacy]"
TypedSpan
Fix: Updated type annotations to use consistent Union types
Downside: None - purely cosmetic type annotation changes with no runtime impact.
🟢 LOW RISK -
interaction_types.py
(line 81)Original Error:
Argument of type "List[dict[Unknown, Unknown]] | None" cannot be assigned to parameter "events" of type "List[dict[Unknown, Unknown]]"
Fix: Added null coalescing operator
Downside: None - safe fallback to empty list when None, maintains existing behavior expectations.
Files Changed
nemoguardrails/tracing/interaction_types.py
(1 line changed)nemoguardrails/tracing/span_extractors.py
(22 lines changed, 14 deletions, 8 additions)nemoguardrails/tracing/tracer.py
(4 lines added)All fixes preserve existing functionality while making the code fully type-safe.
Test Plan
Type-checking
Unit-tests
Local CLI check
Related Issue(s)
Top-level PR to merge into before develop-branch merge: #1367
Checklist