-
Notifications
You must be signed in to change notification settings - Fork 547
chore(types): Type-clean colang/ (111 errors) #1381
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
Open
tgasser-nv
wants to merge
2
commits into
develop
Choose a base branch
from
chore/type-clean-colang
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tagging @cparisien, @Pouyanpi , @trebedea for review |
19 tasks
Documentation preview |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
f5e281f
to
489b2a3
Compare
… branch" This reverts commit 71d00f0.
b4a4f85
to
f507ea0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Summary
The fixes follow a defensive programming approach, adding extensive null checks, type conversions, and error handling. Most changes are low-risk improvements to code safety and type checker compliance. The high-risk changes involve disabling functionality (
_insert_topic_flow_definition
) and changing exception handling patterns, which could affect error reporting behavior.High Risk Fixes
1. Missing Method Implementation (reportAttributeAccessIssue)
nemoguardrails/colang/v1_0/lang/colang_parser.py
, line 793# TODO: Implement topic flow definition insertion
and early return2. Exception Attribute Assignment (reportAttributeAccessIssue)
nemoguardrails/colang/v1_0/lang/colang_parser.py
, lines 1770-1772setattr(exception, "filename", self.filename)
setattr()
to dynamically add attributes to Exception objects. This changes how error information is attached to exceptions.Medium Risk Fixes
3. Null Safety Checks (reportOptionalMemberAccess)
nemoguardrails/colang/runtime.py
, line 37config.imported_paths.values() if config.imported_paths else []
4. Dynamic Attribute Access (reportAttributeAccessIssue)
nemoguardrails/colang/runtime.py
, lines 42-58getattr(self, "_run_output_rails_in_parallel_streaming")
getattr()
instead of direct attribute access. This is safer but changes how missing attributes are handled.5. Type Conversion (reportOperatorIssue)
nemoguardrails/colang/v1_0/lang/colang_parser.py
, line 267self.text += " anonymous-" + str(flow_hash)
6. Dictionary Type Safety (reportArgumentType)
nemoguardrails/colang/v1_0/lang/colang_parser.py
, line 339Low Risk Fixes
7. Type Annotations (Various)
Optional[Dict[str, Any]]
8. Import Organization (reportMissingImports)
TYPE_CHECKING
imports and conditional imports9. Null Checks for Optional Values (reportOptionalSubscript)
self.next_line["indentation"] if self.next_line else 0
10. Variable Initialization (reportPossiblyUnboundVariable)
nemoguardrails/colang/v1_0/lang/utils.py
, line 103multiline_indentation = 0
Summary
The fixes follow a defensive programming approach, adding extensive null checks, type conversions, and error handling. Most changes are low-risk improvements to code safety and type checker compliance. The high-risk changes involve disabling functionality (
_insert_topic_flow_definition
) and changing exception handling patterns, which could affect error reporting behavior.The extensive use of null checks and type guards suggests the codebase handles many optional/nullable values, and these fixes make the handling more explicit and safer.
The report has been generated and is available above. The analysis shows that while most of the type error fixes are low-risk defensive programming improvements, there are a few high-risk changes that disable functionality or change error handling behavior. The fixes generally follow good practices for type safety and null handling in Python codebases.
Test Plan
Type-checking
Unit-tests
poetry run pytest --quiet ........................................................................................sssssss.s......ss...................... [ 8%] ......................................ss......ss................s.......................s............s......................... [ 17%] ....................................................s.......................................................................... [ 26%] ...................................sssss..................ssss..........................................................s.....s [ 35%] s.................ssssssss.ssssssssss.....................................s...................................ssssssss......... [ 44%] .....sss...ss...ss............................sssssssssssss.................................................................... [ 52%] ..............s..........................................................................................sssssssss.........ss.. [ 61%] ...................................................................................................ssssssss.................... [ 70%] ............................................s................................s................................................. [ 79%] ............................................................................................................................... [ 88%] ............................................................................................................................... [ 97%] .....................s..................... [100%] 1340 passed, 100 skipped in 109.88s (0:01:49)
Local CLI check
Related Issue(s)
Top-level PR to merge into before develop-branch merge: #1367
Checklist