Skip to content

Fix _python_version parsing for pre-release Python versions - #2917

Open
laasyapriya2007 wants to merge 1 commit into
apple:mainfrom
laasyapriya2007:fix-python-version-rc-parsing
Open

laasyapriya2007 wants to merge 1 commit into
apple:mainfrom
laasyapriya2007:fix-python-version-rc-parsing

Conversation

@laasyapriya2007

Copy link
Copy Markdown

Fixes #2874

_python_version() parsed sys.version with int(), which raises a ValueError on pre-release interpreters such as 3.15.0rc2, since "0rc2" is not a valid integer. Use sys.version_info.major/.minor/.micro instead, which always provides the version components as integers and correctly handles alpha, beta, RC and other pre-release versions.

Applied the same fix to the duplicate helper in coremltools/test/optimize/torch/utils.py, and added a unit test verifying _python_version() returns exactly three integer components.

Testing (Python 3.14.0, Windows):

  • pytest coremltools/test/models/test_utils.py → 1 passed
  • from coremltools.test.optimize.torch.utils import _python_version → (3, 14, 0)
  • pytest coremltools/test/api/test_api_visibilities.py → one pre-existing failure (libmilstoragepython/libmodelpackage compiled extensions not available on Windows); reproduces on base commit

_python_version() parsed sys.version with int(), which raises a
ValueError on pre-release interpreters such as 3.15.0rc2, since
"0rc2" is not a valid integer. Use sys.version_info instead, which
always provides major/minor/micro as integers and handles alpha,
beta, RC and other pre-release versions.

Same fix applied to the duplicate helper in
coremltools/test/optimize/torch/utils.py, and a unit test added
verifying _python_version() returns exactly three integer components.

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.

_python_version in coremltools/models/utils.py doesn't handle RCs and other possible versions

1 participant