Skip to content

Fix test_python_get_preferred_default for rc Python releases#10478

Merged
Secrus merged 1 commit intopython-poetry:mainfrom
hroncok:test_python_get_preferred_default_rc
Jul 31, 2025
Merged

Fix test_python_get_preferred_default for rc Python releases#10478
Secrus merged 1 commit intopython-poetry:mainfrom
hroncok:test_python_get_preferred_default_rc

Conversation

@hroncok
Copy link
Copy Markdown
Contributor

@hroncok hroncok commented Jul 29, 2025

This is a followup for bca92d5

Apparently, sys.version_info has "candidate" in it:

>>> sys.version_info[:5]
(3, 14, 0, 'candidate', 1)

And that is not a valid PEP 440 version:

poetry.core.version.exceptions.InvalidVersionError: Invalid PEP 440 version: '3.14.0.candidate.1'

This makes the test pass with 3.14.0rc1.

Summary by Sourcery

Bug Fixes:

  • Adjust test_python_get_preferred_default to convert 'candidate' in sys.version_info to 'rc' for valid PEP 440 version parsing

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Jul 29, 2025

Reviewer's Guide

Refactored the version string computation in the test for get_preferred_python to explicitly handle final, candidate (RC), and other version markers, ensuring RC releases are correctly parsed per PEP 440.

File-Level Changes

Change Details Files
Replace version_len slicing with explicit version_info branching
  • Remove version_len variable and its conditional assignment
  • Add if-elif-else block to set version_info for final, candidate, and other statuses
  • Use version_info tuple for constructing the version string
tests/utils/test_python_manager.py
Map 'candidate' marker to 'rc' for release candidates
  • Detect sys.version_info[3] == 'candidate'
  • Build version_info with 'rc' and release number from sys.version_info[4]
tests/utils/test_python_manager.py

Possibly linked issues

  • #0: The PR fixes the test_python_get_preferred_default failure with Python pre-releases by correctly parsing sys.version_info to handle different release stages, as described in the issue.
  • Add src to sys.path if module is in src #123: The PR fixes the test failure reported in the issue by correctly parsing 3.14-rc Python versions.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @hroncok - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Secrus
Secrus previously approved these changes Jul 29, 2025
@hroncok
Copy link
Copy Markdown
Contributor Author

hroncok commented Jul 30, 2025

I got:

tests/utils/test_python_manager.py:57: error: Incompatible types in assignment (expression has type "tuple[int, int, int, str, int]", variable has type "tuple[int, int, int]")  [assignment]
tests/utils/test_python_manager.py:59: error: Incompatible types in assignment (expression has type "tuple[int, int, int, Literal['alpha', 'beta', 'candidate', 'final'], int]", variable has type "tuple[int, int, int]")  [assignment]

Will try to fight that.

@hroncok hroncok force-pushed the test_python_get_preferred_default_rc branch from 31b6c42 to 12423a0 Compare July 30, 2025 09:11
This is a followup for bca92d5

Apparently, sys.version_info has "candidate" in it:

    >>> sys.version_info[:5]
    (3, 14, 0, 'candidate', 1)

And that is not a valid PEP 440 version:

    poetry.core.version.exceptions.InvalidVersionError: Invalid PEP 440 version: '3.14.0.candidate.1'

This makes the test pass with 3.14.0rc1.
@hroncok hroncok force-pushed the test_python_get_preferred_default_rc branch from 12423a0 to 69df76e Compare July 30, 2025 09:12
@hroncok hroncok requested a review from Secrus July 30, 2025 09:17
@Secrus Secrus merged commit 3d0ae4e into python-poetry:main Jul 31, 2025
53 checks passed
radoering pushed a commit that referenced this pull request Aug 4, 2025
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants