Fix: Resolve pytype --strict-none-binding issue in the api client #3214
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.
This PR addresses pytype errors raised by the
--strict-none-binding
flag in the api clientSearch
class. The issue stemmed fromself._raw_response
being initialized toNone
and then populated later by_execute_query
, leading to potential unsoundness when accessing it directly.The fix modifies
_execute_query
to always return a value: a dictionary with the search results if the results are not saved to a file andcount=False
, the total count ifcount=True
, orNone
if the results are saved to a file. Theto_dict
method now calls_execute_query
ifself._raw_response
isNone
and handles the case where_execute_query
returnsNone
(indicating a previousto_file
call) by raising a ValueError. This approach avoids the less robust solution of using assertions and ensures thatto_pandas
and other methods always have a valid dictionary to work with.A similar issue was fixed in
story.py
to handle cases where a view block did not have a populatedview
attribute, preventing a potential error.These changes improve type safety and robustness in the
Search
andStory
classes.