Repository navigation
Add Python::version() & PythonVersionInfo::kind - #6652
bschoenmaeckers wants to merge 3 commits into
Conversation
069c0ae to
0b52d25
Compare
0d2e819 to
d28314c
Compare
d28314c to
69cbc56
Compare
3ea21b9 to
09bd587
Compare
|
|
||
| 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(); |
There was a problem hiding this comment.
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+?
|
LGTM but might be nice to get @davidhewitt's opinion on the API change |
| } | ||
|
|
||
| impl PartialEq<(u8, u8)> for PythonVersionInfo { | ||
| fn eq(&self, other: &(u8, u8)) -> bool { |
There was a problem hiding this comment.
just BTW, shouldn't we make the equality and order methods inline?
|
|
||
| PythonVersionInfo::from_str(version_number_str).unwrap() | ||
| #[inline] | ||
| pub fn version() -> PythonVersionInfo { |
There was a problem hiding this comment.
Another bold idea is to drop PythonVersionInfo & PythonVersionKind entirely and just return (u8, u8, u8) directly?
There was a problem hiding this comment.
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 deprecates
Python::version_infooverPython::version&Python::full_version_infothat do not require aPythontoken.Python::versionuses the staticPy_Versionvalue without need for string parsing which will lead to trivial version checks.