fix(api-client): code hygiene - #3867
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request systematically adds and updates Google-style docstrings across the Timesketch Python API client, removes deprecated unicode_literals imports, and standardizes mock imports in tests. It also introduces a DEFAULT_CONFIG_SECTION constant. The review feedback points out several type and module path inaccuracies in the newly added docstrings, specifically regarding the types of client_id, event_id, and index_id (which should be str instead of int), and the module path for TimesketchApi (which should reference the client module rather than api).
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive type annotations, future annotations imports, and import cleanups across the Timesketch API client codebase. However, several issues were identified during the review: a critical syntax error in the Sketch.__init__ method due to a missing closing parenthesis and return type; a bug in story.py where stringifying block.data on a TextBlock outputs a dictionary string instead of the text; a potential crash in story.py when parsing empty content with json.loads(); and a regression in sketch.py where default field handling in export_events_stream explicitly requests zero fields instead of all fields.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request widely introduces type hints and annotations across the timesketch_api_client library to improve code clarity and enable static analysis. However, several critical issues were identified during the review. Most notably, merge or copy-paste errors in client.py and sketch.py have introduced duplicated imports, TYPE_CHECKING blocks, and method definitions that will cause syntax errors. Additionally, there is a potential TypeError in aggregation.py when accessing a potentially missing 'meta' key, a redundant bytes cast in crypto.py, and minor docstring mismatches. Finally, multiple instances of string formatting using .format() violate the repository's style guide, which prefers f-strings.
| meta = self.resource_data.get("meta") | ||
| meta["name"] = name |
There was a problem hiding this comment.
The call self.resource_data.get("meta") can return None if the "meta" key does not exist in self.resource_data. The subsequent access meta["name"] = name would then raise a TypeError. To prevent this, you should provide a default empty dictionary, similar to how it's handled in the description setter on line 343.
| meta = self.resource_data.get("meta") | |
| meta["name"] = name | |
| meta = self.resource_data.get("meta", {}) | |
| backend=backends.default_backend(), | ||
| ) | ||
| return base64.urlsafe_b64encode(kdf.derive(password)) | ||
| return bytes(base64.urlsafe_b64encode(kdf.derive(password))) |
There was a problem hiding this comment.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request primarily adds type hints, f-strings, and updated docstrings across various modules of the Timesketch API client to improve code quality and maintainability. The code review feedback highlights several issues that need to be addressed: potential TypeError crashes in aggregation.py when self.resource_data is None, duplicated if TYPE_CHECKING: blocks in client.py and sketch.py, and consecutively duplicated lines of code in sketch.py for retrieving the sketch name and processing permissions.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Removed
from __future__ import unicode_literalsfrom all api-client as we are py3 only.Complete Parameter Coverage:
* Ensured every parameter in function signatures is documented in the Args: section.
* Added documentation for init parameters
* Added Args: sections to property setters (e.g., name, description, color, status, max_entries)
which were previously undocumented.
Added
from __future__ import annotationsin a lot of files to ensure typing works across various Python3 versionsType Accuracy: improved type accuracy in docstrings
Added docstrings to most of api-client methods.