Skip to content

cli_client: Narrow api_client type in TimesketchCli.__init__ to satisfy Pytype - #3897

Open
jaegeral wants to merge 5 commits into
google:masterfrom
jaegeral:2026-08-08-20_prefly_cli
Open

cli_client: Narrow api_client type in TimesketchCli.__init__ to satisfy Pytype#3897
jaegeral wants to merge 5 commits into
google:masterfrom
jaegeral:2026-08-08-20_prefly_cli

Conversation

@jaegeral

@jaegeral jaegeral commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Restructure TimesketchCli.init assignment with an if/else guard to narrow
api_client from Optional[TimesketchApi] to TimesketchApi

Added error handling for uninitialized API client.
@jaegeral
jaegeral requested a review from jkppr August 20, 2026 12:44
@jaegeral jaegeral self-assigned this Aug 20, 2026
@jaegeral jaegeral changed the title Check API client initialization before proceeding Check API client initialization in cli client before proceeding Aug 20, 2026
Added an error message to the assertion for better debugging.
@jaegeral

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an assertion to ensure the Timesketch API client is initialized before retrieving a sketch. The review feedback correctly points out that using assert for runtime validation is discouraged in Python because assertions can be optimized out in production. It is recommended to replace the assertion with an explicit conditional check that raises a RuntimeError.

Comment thread cli_client/python/timesketch_cli_client/cli.py Outdated
Returns:
Sketch object.
"""
assert self.api is not None, "Timesketch API client is not initialized"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than asserting inside the sketch property getter, would it make more sense to establish this at the end of TimesketchCli.__init__ instead?

This would also cover other places where self.api is used.

jaegeral and others added 2 commits August 20, 2026 16:35
Refactor API client initialization and type annotation.
@jaegeral jaegeral changed the title Check API client initialization in cli client before proceeding cli_client: Narrow api_client type in TimesketchCli.__init__ to satisfy Pytype Aug 20, 2026
@jaegeral
jaegeral requested a review from jkppr August 20, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants