Skip to content

docs: add docstrings or explicit overrides to dump and as_write methods - #2793

Open
MortGron wants to merge 2 commits into
masterfrom
override-dump-without-docstring
Open

docs: add docstrings or explicit overrides to dump and as_write methods#2793
MortGron wants to merge 2 commits into
masterfrom
override-dump-without-docstring

Conversation

@MortGron

@MortGron MortGron commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Description

Many public methods do not have docstrings. It is possible to automate the check for missing docstrings using https://docs.astral.sh/ruff/rules/undocumented-public-method/.

This requires all public methods either to have a docstring, or to have a decorater indicating why they should not. The most common scenario is that a method inherits the docstring from some parent class. However, that this is the intention must be made clear by using the @override decorater introduced in Python 3.12 (and available in typing_extensions).

Because enabling this automated check will require a vast number of code line changes, it has been split up into multiple PRs. In this PR almost all dump and as_write methods have either got the override decorator or have got a docstring.

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • The PR title follows the Conventional Commit spec.

@MortGron
MortGron marked this pull request as ready for review August 26, 2026 08:30
@MortGron
MortGron requested review from a team as code owners August 26, 2026 08:30

@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 systematically adds the @override decorator to overridden methods (primarily dump and as_write) across various CogniteResource subclasses to improve type safety and consistency. Feedback suggests applying the @override decorator to TransformationBlockedInfo.dump in cognite/client/data_classes/transformations/common.py for consistency with the rest of the changes.

Comment on lines 487 to 489
def dump(self, camel_case: bool = True) -> dict[str, Any]:
"""Dump the instance into a json serializable Python data type."""
return basic_obj_dump(self, camel_case)

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.

high

For consistency with other CogniteResource subclasses in this file and across the codebase, TransformationBlockedInfo.dump should use the @override decorator instead of a duplicate docstring.

Suggested change
def dump(self, camel_case: bool = True) -> dict[str, Any]:
"""Dump the instance into a json serializable Python data type."""
return basic_obj_dump(self, camel_case)
@override
def dump(self, camel_case: bool = True) -> dict[str, Any]:
return basic_obj_dump(self, camel_case)
References
  1. Consistency: Follow established patterns across the codebase (link)

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.16667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.11%. Comparing base (7891f53) to head (35af118).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...a_classes/data_modeling/extractor_extensions/v1.py 0.00% 2 Missing ⚠️
cognite/client/data_classes/datapoints.py 92.85% 1 Missing ⚠️
...te/client/data_classes/transformations/__init__.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2793      +/-   ##
==========================================
+ Coverage   93.07%   93.11%   +0.04%     
==========================================
  Files         516      516              
  Lines       53263    53687     +424     
==========================================
+ Hits        49572    49990     +418     
- Misses       3691     3697       +6     
Files with missing lines Coverage Δ
cognite/client/data_classes/_base.py 93.64% <100.00%> (+0.02%) ⬆️
cognite/client/data_classes/agents/agent_tools.py 98.81% <100.00%> (+0.10%) ⬆️
cognite/client/data_classes/agents/agents.py 100.00% <100.00%> (ø)
cognite/client/data_classes/agents/chat.py 97.22% <100.00%> (+0.13%) ⬆️
cognite/client/data_classes/aggregations.py 89.53% <100.00%> (+0.24%) ⬆️
...client/data_classes/annotation_types/primitives.py 98.73% <100.00%> (+0.01%) ⬆️
cognite/client/data_classes/annotations.py 97.91% <100.00%> (+0.06%) ⬆️
cognite/client/data_classes/assets.py 94.50% <100.00%> (+0.05%) ⬆️
cognite/client/data_classes/capabilities.py 97.07% <100.00%> (+<0.01%) ⬆️
cognite/client/data_classes/contextualization.py 91.25% <100.00%> (+0.06%) ⬆️
... and 54 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant