Skip to content

feat(simulators): make clear what is the default value of the sort argument in simulation runs list#2695

Open
MortGron wants to merge 1 commit into
masterfrom
simulations-runs-list-sort-default
Open

feat(simulators): make clear what is the default value of the sort argument in simulation runs list#2695
MortGron wants to merge 1 commit into
masterfrom
simulations-runs-list-sort-default

Conversation

@MortGron

Copy link
Copy Markdown
Contributor

Description

Make clear what is the default sort order for simulations runs list.

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 June 17, 2026 13:38
@MortGron MortGron requested review from a team as code owners June 17, 2026 13:38

@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 changes the default value of the 'sort' parameter in the simulator runs 'list' method from 'None' to 'SimulationRunsSort()'. The reviewer advises against using a complex object as a default argument in the function signature, as it is a Python anti-pattern and introduces a breaking change for callers explicitly passing 'None'. Instead, the reviewer recommends keeping 'sort: SimulationRunsSort | None = None' in the signature, handling the default value inline within the function body, and updating the docstrings to reflect this.

created_time: TimestampRange | None = None,
simulation_time: TimestampRange | None = None,
sort: SimulationRunsSort | None = None,
sort: SimulationRunsSort = SimulationRunsSort(),

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

Avoid using mutable or complex objects like SimulationRunsSort() as default arguments in function signatures. This is a well-known Python anti-pattern because default arguments are evaluated once at function definition time, which can lead to shared state bugs. Additionally, removing None from the allowed types of sort is a breaking change for any caller explicitly passing None (e.g., when forwarding arguments).

Please keep sort: SimulationRunsSort | None = None in the signature and handle the default value inside the function body.

Suggested change
sort: SimulationRunsSort = SimulationRunsSort(),
sort: SimulationRunsSort | None = None,
References
  1. Consistency: Follow established patterns across the codebase. Other list methods and call use sort: SomethingSort | None = None. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we wanted to enforce this rule, we could enable https://docs.astral.sh/ruff/rules/mutable-argument-default/#mutable-argument-default-b006. However, is not currently enabled. Also, the function does not mutate this argument, so there is no risk.

The change is breaking, but simulators is in alpha.

Comment thread cognite/client/_api/simulators/runs.py
Comment thread cognite/client/_api/simulators/runs.py
Comment thread cognite/client/_sync_api/simulators/runs.py
Comment thread cognite/client/_sync_api/simulators/runs.py
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.66%. Comparing base (9ecf95c) to head (0894085).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2695      +/-   ##
==========================================
- Coverage   93.70%   93.66%   -0.04%     
==========================================
  Files         503      503              
  Lines       50699    50699              
==========================================
- Hits        47505    47488      -17     
- Misses       3194     3211      +17     
Files with missing lines Coverage Δ
cognite/client/_api/simulators/runs.py 100.00% <ø> (ø)
cognite/client/_sync_api/simulators/runs.py 100.00% <ø> (ø)

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

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