Skip to content

sqlite3: handle int type in Connection.timeout parameter#7237

Merged
youknowone merged 1 commit intoRustPython:mainfrom
ever0de:fix/support-sqlite3-timeout-type-handling
Feb 28, 2026
Merged

sqlite3: handle int type in Connection.timeout parameter#7237
youknowone merged 1 commit intoRustPython:mainfrom
ever0de:fix/support-sqlite3-timeout-type-handling

Conversation

@ever0de
Copy link
Copy Markdown
Contributor

@ever0de ever0de commented Feb 27, 2026

Summary by CodeRabbit

  • Improvements
    • SQLite connection timeout now accepts both floating‑point and integer values, making it easier to supply timeouts in seconds or as whole numbers. The change is backward compatible: existing defaults and behavior are preserved while allowing mixed input types for more flexible configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d540e3f and 4385cc7.

⛔ Files ignored due to path filters (2)
  • Lib/test/test_sqlite3/test_dbapi.py is excluded by !Lib/**
  • Lib/test/test_sqlite3/test_transactions.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/_sqlite3.rs

📝 Walkthrough

Walkthrough

The SQLite connection timeout argument now accepts either a float or an integer via Either<f64, i64]. Initialization pattern-matches the variant, using the float directly or converting the integer to milliseconds, preserving previous behavior while allowing mixed input types.

Changes

Cohort / File(s) Summary
SQLite3 Timeout Type Extension
crates/stdlib/src/_sqlite3.rs
Changed ConnectArgs.timeout from f64 to Either<f64, i64>. Added Either to imports and updated initialize_db to pattern-match Either::A(f) or Either::B(i), converting integer timeouts to milliseconds and producing a c_int timeout value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibbled code beneath the moonlight,
Timeout types now dance just right.
Float or int, both find their way,
Soft hops of logic save the day. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for integer type in the Connection.timeout parameter, which aligns with the switch from f64 to Either<f64, i64> type.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 27, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/sqlite3
[ ] test: cpython/Lib/test/test_sqlite3 (TODO: 80)

dependencies:

  • sqlite3

dependent tests: (2 tests)

  • sqlite3: test_dbm_sqlite3 test_sqlite3

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@ever0de ever0de marked this pull request as ready for review February 27, 2026 07:23
#[pyarg(any, default = 5.0)]
timeout: f64,
#[pyarg(any, default = Either::A(5.0))]
timeout: Either<f64, i64>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Parsing timeout as Either<f64, i64> is a common pattern in Python. If you are interested in, investigating if introducing TimeoutSeconds utility type will be useful or not. (I am not sure yet)

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.

I also think it's a great idea. Do you think it would be better to separate it into a new PR instead of working on it here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sure, in separate PR. it is unrelated refactoring

@youknowone youknowone force-pushed the fix/support-sqlite3-timeout-type-handling branch from d540e3f to 4385cc7 Compare February 27, 2026 11:58
@youknowone youknowone merged commit 81acb9b into RustPython:main Feb 28, 2026
23 of 25 checks passed
ever0de added a commit to ever0de/RustPython that referenced this pull request Feb 28, 2026
Follow-up refactoring from RustPython#7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).
ever0de added a commit to ever0de/RustPython that referenced this pull request Feb 28, 2026
Follow-up refactoring from RustPython#7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).
ever0de added a commit to ever0de/RustPython that referenced this pull request Mar 1, 2026
Follow-up refactoring from RustPython#7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).
ever0de added a commit to ever0de/RustPython that referenced this pull request Mar 8, 2026
Follow-up refactoring from RustPython#7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).
youknowone pushed a commit that referenced this pull request Mar 9, 2026
* Introduce TimeoutSeconds utility type for timeout parameters

Follow-up refactoring from #7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).

* Validate timeout in ThreadHandle::join to prevent panic

* refactor: move TimeoutSeconds from number to time module
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Mar 22, 2026
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Mar 22, 2026
…hon#7271)

* Introduce TimeoutSeconds utility type for timeout parameters

Follow-up refactoring from RustPython#7237.

Python timeout parameters typically accept both float and int. Several
places in the codebase used Either<f64, i64> for this, each repeating
the same match-and-convert boilerplate. This extracts that into a
TimeoutSeconds type in vm::function::number.

Refactored sites:
- _sqlite3::ConnectArgs.timeout
- _thread::AcquireArgs.timeout
- _thread::ThreadHandle::join timeout

Either<f64, i64> in time.rs (6 sites) left unchanged: those are
timestamp values with per-branch logic (floor, range checks, etc).
Either<f64, isize> in select.rs also left unchanged (different type).

* Validate timeout in ThreadHandle::join to prevent panic

* refactor: move TimeoutSeconds from number to time module
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