Skip to content

Add Python::version() & PythonVersionInfo::kind - #6652

Open
bschoenmaeckers wants to merge 3 commits into
PyO3:mainfrom
bschoenmaeckers:version_info_hex
Open

bschoenmaeckers wants to merge 3 commits into
PyO3:mainfrom
bschoenmaeckers:version_info_hex

Conversation

@bschoenmaeckers

Copy link
Copy Markdown
Member

This deprecates Python::version_info over Python::version & Python::full_version_info that do not require a Python token.

Python::version uses the static Py_Version value without need for string parsing which will lead to trivial version checks.

@bschoenmaeckers
bschoenmaeckers force-pushed the version_info_hex branch 2 times, most recently from 069c0ae to 0b52d25 Compare December 2, 2026 12:37
Comment thread src/version.rs Resolved
Comment thread tests/test_declarative_module.rs Resolved
Comment thread src/internal/get_slot.rs

static IS_RUNTIME_3_10: PyOnceLock<bool> = PyOnceLock::new();
*IS_RUNTIME_3_10.get_or_init(py, || py.version_info() >= (3, 10))
static IS_RUNTIME_3_10: OnceCell<bool> = OnceCell::new();

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.

maybe dumb idea: instead of having a once_cell per Python::version() usage, what about having it one in Python::version for below 3.11 to cache the version string parsing and skip the cell completely for 3.11+?

Comment thread src/version.rs Resolved
Comment thread src/version.rs Resolved
@Tpt

Tpt commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

LGTM but might be nice to get @davidhewitt's opinion on the API change

Comment thread src/version.rs
}

impl PartialEq<(u8, u8)> for PythonVersionInfo {
fn eq(&self, other: &(u8, u8)) -> bool {

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.

just BTW, shouldn't we make the equality and order methods inline?

Comment thread src/marker.rs

PythonVersionInfo::from_str(version_number_str).unwrap()
#[inline]
pub fn version() -> PythonVersionInfo {

@bschoenmaeckers bschoenmaeckers Dec 2, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Another bold idea is to drop PythonVersionInfo & PythonVersionKind entirely and just return (u8, u8, u8) directly?

@Tpt Tpt Dec 4, 2026 •

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.

Might be nice. Imho the struct is a bit more readable if you want to e.g. only extract the major version (my_version.major instead of my_version.0) but I am not sure if it's a real use case

This branch has not been deployed

No deployments
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