Skip to content

Fix custom docstr formatter to work with dataclasses#2494

Merged
haakonvt merged 5 commits intopysdk-release-v8from
fix-custom-docstr-linter-for-dataclasses
Feb 27, 2026
Merged

Fix custom docstr formatter to work with dataclasses#2494
haakonvt merged 5 commits intopysdk-release-v8from
fix-custom-docstr-linter-for-dataclasses

Conversation

@haakonvt
Copy link
Contributor

While editing signatures lazily awaiting automatic correction by pre-commit, I was surprised to see no changes. I quickly realized our custom docstring formatter was not so fond of dataclasses 😅

@haakonvt haakonvt requested review from a team as code owners February 26, 2026 22:48
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the custom docstring linter was not correctly handling dataclasses, leading to formatting inconsistencies. The changes involve updating the linter's logic to properly parse and format docstrings for dataclasses, and applying the necessary docstring corrections across several data class files to align with the linter's expected format. This ensures consistent and accurate documentation for data classes throughout the codebase.

Highlights

  • Docstring Linter Fix: The custom docstring linter has been updated to correctly process dataclasses, resolving previous formatting inconsistencies.
  • Docstring Standardization: Docstrings across numerous data class files have been standardized, including consistent use of single quotes for Literal types, correct argument ordering, and refined type hints.
  • Improved Error Messaging: The docstring formatter now provides more detailed error messages, including the class/function and method description, to aid in debugging.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cognite/client/data_classes/agents/agent_tools.py
    • Updated literal type hints from double to single quotes.
    • Corrected type hint for 'version' argument.
    • Reordered 'type' and 'description' arguments in docstring.
  • cognite/client/data_classes/agents/chat.py
    • Reordered 'data' and 'type' arguments in docstring.
    • Cleaned up 'content' description and updated literal type hints.
    • Updated literal type hints from double to single quotes for 'status' and 'role'.
  • cognite/client/data_classes/ai.py
    • Standardized spacing in 'NodeId | None' type hint.
    • Corrected argument name from 'content' to 'references' in docstring.
  • cognite/client/data_classes/data_modeling/containers.py
    • Adjusted 'constraints' and 'indexes' type hints to remove '| None' where not applicable.
    • Reordered arguments in docstrings for 'ContainerApply' and 'Container'.
  • cognite/client/data_classes/data_modeling/debug.py
    • Refined type hints for 'query' and 'parameters' from 'object' to 'dict[str, Any]'.
  • cognite/client/data_classes/data_modeling/instances.py
    • Updated type hint for 'properties' from 'PropertyValue' to 'PropertyValueWrite'.
    • Added generic type parameters to 'NodeList' and 'EdgeList' in docstring.
  • cognite/client/data_classes/data_modeling/query.py
    • Updated type hints for 'with_', 'select', 'parameters', and 'cursors'.
    • Reordered and refined type hints for arguments in 'EdgeResultSetExpression' and 'EdgeResultSetExpressionSync' docstrings.
  • cognite/client/data_classes/data_modeling/views.py
    • Consolidated multiline descriptions for 'type', 'edge_source', and 'direction' into single lines in docstrings.
  • cognite/client/data_classes/datapoints.py
    • Updated type hints for 'id', 'external_id', 'instance_id', 'before', 'include_status', 'ignore_bad_datapoints', and 'treat_uncertain_as_bad'.
  • cognite/client/data_classes/datapoints_subscriptions.py
    • Reordered 'partitions' and 'has_next' arguments in docstring.
  • cognite/client/data_classes/simulators/models.py
    • Corrected type hint for 'file' from 'int' to 'SimulatorModelDependencyFileReference'.
  • cognite/client/data_classes/simulators/routine_revisions.py
    • Standardized literal type hints from double to single quotes across multiple arguments.
  • cognite/client/data_classes/workflows.py
    • Updated type hint for 'version' from 'str, optional' to 'str | None'.
  • scripts/custom_checks/docstrings.py
    • Removed unused import 'is_dataclass'.
    • Corrected 'repr' method for 'ReturnParam' class.
    • Adjusted '_parse_returns_section' method signature and call to remove unused 'indent' parameter.
    • Enhanced 'docstring_is_correct' and '_create_docstring_return_description' methods to properly handle dataclass return annotations.
    • Improved error message in 'update_py_file' for better debugging.
    • Removed redundant 'is_dataclass' check in 'format_docstring_class_methods'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 fixes a custom docstring linter to correctly handle dataclasses and applies the resulting formatting changes across the codebase. The changes are mostly related to docstring formatting and improving type hints. I've found a logic bug in the linter fix itself that may prevent it from correcting certain invalid docstrings in dataclass __init__ methods. A suggestion to fix this has been provided.

@haakonvt haakonvt force-pushed the fix-custom-docstr-linter-for-dataclasses branch from 66cd067 to 74d5d91 Compare February 26, 2026 23:27
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.63%. Comparing base (f95e69a) to head (7d5b8a2).
⚠️ Report is 7 commits behind head on pysdk-release-v8.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           pysdk-release-v8    #2494      +/-   ##
====================================================
+ Coverage             64.59%   64.63%   +0.03%     
====================================================
  Files                   467      467              
  Lines                 47729    47729              
====================================================
+ Hits                  30832    30850      +18     
+ Misses                16897    16879      -18     
Files with missing lines Coverage Δ
cognite/client/data_classes/agents/agent_tools.py 31.28% <ø> (ø)
cognite/client/data_classes/agents/agents.py 50.00% <ø> (ø)
cognite/client/data_classes/agents/chat.py 37.96% <ø> (ø)
cognite/client/data_classes/ai.py 11.84% <ø> (ø)
...te/client/data_classes/data_modeling/containers.py 42.26% <ø> (ø)
cognite/client/data_classes/data_modeling/debug.py 33.45% <ø> (ø)
...ite/client/data_classes/data_modeling/instances.py 49.94% <ø> (ø)
cognite/client/data_classes/data_modeling/query.py 55.70% <ø> (ø)
cognite/client/data_classes/data_modeling/views.py 49.22% <ø> (ø)
cognite/client/data_classes/datapoints.py 57.23% <ø> (ø)
... and 4 more

... and 7 files 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.

@haakonvt haakonvt changed the title Fix custom docstr linter for dataclasses Fix custom docstr formatter to work with dataclasses Feb 27, 2026
Comment on lines +204 to +205
with_ (MutableMapping[str, _T_ResultSetExpression]): A dictionary of result set expressions to use in the query. The keys are used to reference the result set expressions in the select and parameters.
select (MutableMapping[str, _T_Select]): A dictionary of select expressions to use in the query. The keys must match the keys in the with\_ dictionary. The select expressions define which properties to include in the result set.
Copy link
Contributor

Choose a reason for hiding this comment

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

is this change expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, it does match the base class "directly", but doesn't take into account that we pass
ResultSetExpressionSync for _T_ResultSetExpression, and SelectSync for _T_Select.

I don't think it is worth diving to much into, so I'll add a manual override here instead.

@dataclass
class QueryBase(CogniteResource, ABC, Generic[_T_ResultSetExpression, _T_Select]):
    """Abstract base class for normal queries and sync queries"""

    with_: MutableMapping[str, _T_ResultSetExpression]
    select: MutableMapping[str, _T_Select]
    parameters: Mapping[str, PropertyValue] = field(default_factory=dict)
    cursors: Mapping[str, str | None] = field(default_factory=dict)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's interesting is that class Query(QueryBase["ResultSetExpression", Select]): seems to work as expected... mysterious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HA! Not so mysterious:

CLS_METHOD_EXCEPTIONS = {
    (Query, "__init__"),  # Reason: Uses a parameter 'with_'; and we need to escape the underscore
    (FunctionHandle, "__init__"),  # Reason: Protocol class doesn't have __init__ with return type
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@polomani fixed now!

@haakonvt
Copy link
Contributor Author

🦄

@haakonvt haakonvt self-assigned this Feb 27, 2026
@haakonvt haakonvt added risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action labels Feb 27, 2026
@haakonvt haakonvt force-pushed the fix-custom-docstr-linter-for-dataclasses branch from 015c894 to 7239e25 Compare February 27, 2026 11:41
@haakonvt
Copy link
Contributor Author

🦄

polomani
polomani previously approved these changes Feb 27, 2026
Copy link
Contributor

@polomani polomani left a comment

Choose a reason for hiding this comment

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

LGTM (i don't have powers here anyway)

@haakonvt haakonvt enabled auto-merge February 27, 2026 11:42
@haakonvt
Copy link
Contributor Author

LGTM (i don't have powers here anyway)

Oh but you do 👨‍🎤

@haakonvt haakonvt force-pushed the fix-custom-docstr-linter-for-dataclasses branch from 7239e25 to 181bd57 Compare February 27, 2026 11:47
@haakonvt haakonvt force-pushed the fix-custom-docstr-linter-for-dataclasses branch from 181bd57 to 7d5b8a2 Compare February 27, 2026 11:52
@haakonvt
Copy link
Contributor Author

🦄

@haakonvt haakonvt disabled auto-merge February 27, 2026 11:53
@haakonvt haakonvt enabled auto-merge February 27, 2026 11:53
@haakonvt haakonvt merged commit 1cf2bdc into pysdk-release-v8 Feb 27, 2026
16 checks passed
@haakonvt haakonvt deleted the fix-custom-docstr-linter-for-dataclasses branch February 27, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants