`ValidationInfo.context` may be `None`, Pylance reports "get" is not a known attribute of "None"
https://github.com/567-labs/instructor/blob/121f901653f92e6d718531cc2a02151d56ad5ca3/examples/reranker/run.py#L24
"get" is not a known attribute of "None" PylancereportOptionalMemberAccess
@claude investigate and fix if possible,
Claude finished @jxnl's task in 1m 53s —— View job • claude/issue-1588-20250610_213255 • Create PR ➔
ValidationInfo.context type issue - Fixed ✅
I've successfully investigated and fixed the Pylance type checking issue where ValidationInfo.context may be None but the code calls .get() on it.
Tasks:
- [x] Read the problematic file (examples/reranker/run.py:24)
- [x] Understand ValidationInfo.context typing
- [x] Implement type-safe fix
- [x] Test and verify the solution
- [x] Commit changes
Analysis:
Found the issue in examples/reranker/run.py:24. The code directly calls .get() on info.context without checking if it's None:
context = info.context
chunks = context.get("chunks", []) # Error: context might be None
Fix Applied:
Added a null check before accessing context methods, following the pattern used in test files:
context = info.context
if context:
chunks = context.get("chunks", [])
if v not in [chunk["id"] for chunk in chunks]:
# validation logic...
This ensures the validator only performs chunk ID validation when context is available, eliminating the Pylance type error while maintaining the same functionality.
Changes Committed:
- File:
examples/reranker/run.py - Change: Added
if context:check before callingcontext.get() - Commit: 29b6c11