Skip to content

feat: allow float timeouts in the clientconfig#2671

Open
MortGron wants to merge 1 commit into
masterfrom
float-timeout
Open

feat: allow float timeouts in the clientconfig#2671
MortGron wants to merge 1 commit into
masterfrom
float-timeout

Conversation

@MortGron

@MortGron MortGron commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

Change the timeout type hint in the ClientConfig to show that non-int, float timouts works.

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 4, 2026 20:48
@MortGron MortGron requested review from a team as code owners June 4, 2026 20:48
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.55%. Comparing base (a233d8a) to head (4924be2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2671      +/-   ##
==========================================
- Coverage   93.59%   93.55%   -0.05%     
==========================================
  Files         492      492              
  Lines       49946    49946              
==========================================
- Hits        46748    46727      -21     
- Misses       3198     3219      +21     
Files with missing lines Coverage Δ
cognite/client/config.py 93.28% <ø> (ø)
tests/tests_integration/conftest.py 83.33% <ø> (ø)

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

@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 updates the type hint of the timeout parameter in ClientConfig from int | None to float | None and adds a float timeout to the integration test client. The review feedback highlights a correctness issue where a timeout of 0.0 would be incorrectly overridden to 60 due to a falsy check, and suggests updating file_transfer_timeout to also support floats. Additionally, the reviewer recommends adding a dedicated unit test for the float timeout configuration instead of relying on the global integration test setup.

Comment thread cognite/client/config.py
cluster: str | None = None,
headers: dict[str, str] | None = None,
timeout: int | None = None,
timeout: float | None = None,

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

While updating the type hint of timeout to float | None, please note that the current implementation in __init__ uses self.timeout = timeout or 60. Since 0.0 is a falsy value in Python, passing timeout=0.0 (which is a valid float timeout for non-blocking/immediate timeout) will be incorrectly overridden to 60.\n\nTo fix this correctness issue, the assignment should be updated to:\npython\nself.timeout = 60 if timeout is None else timeout\n\n\nAdditionally, for consistency and completeness, file_transfer_timeout should also be updated to support float | None instead of strictly int | None.

References
  1. Strong Typing: Use type hints extensively with MyPy. Avoid Any when possible (link)

project=os.environ["COGNITE_PROJECT"],
base_url=os.environ["COGNITE_BASE_URL"],
credentials=credentials,
timeout=59.9, # Test that a non-int timeout works

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

Relying on the global integration test client configuration to verify that float timeouts work is not a robust testing strategy. It doesn't explicitly assert the behavior and could be easily lost or modified in the future.\n\nPlease add a dedicated unit test (e.g., in tests/tests_unit/test_config.py) that instantiates ClientConfig with a float timeout and asserts that client.config.timeout is correctly set to the float value. This ensures explicit test coverage and prevents regressions.

@haakonvt haakonvt 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.

Yagni?

@MortGron

MortGron commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Yagni?

I made this PR because I wanted to set timeout < 1 s. Useful when e.g. troubleshooting authentication issues in a CDF project you know should respond quickly.

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.

2 participants