Skip to content

markers: recognize empty python_version markers #849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

radoering
Copy link
Member

@radoering radoering commented Mar 8, 2025

Without this fix, the intersection of python_version > "3.8" and python_version < "3.9" is not detected as empty marker.

Related to: python-poetry/poetry#10249

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Tests:

  • Add tests to verify that the intersection of mutually exclusive markers is correctly identified as empty.

Copy link

sourcery-ai bot commented Mar 8, 2025

Reviewer's Guide by Sourcery

This pull request fixes an issue where the intersection of certain python_version markers (e.g., python_version > "3.8" and python_version < "3.9") was not being correctly detected as an empty marker. The fix involves modifying the _merge_single_markers function to properly identify these cases and return an EmptyMarker. New tests have been added to verify the fix, and existing tests have been updated to reflect the changes.

Updated class diagram for markers

classDiagram
    class Marker {
        <<Abstract>>
        +name: str
        +value: str
    }
    class EmptyMarker {
        +EmptyMarker()
    }

    Marker <|-- EmptyMarker

    class _merge_single_markers {
        +marker1: Marker
        +marker2: Marker
        +merge_class: type
        +result_constraint: Constraint
        +result_marker: Marker
    }

    note for _merge_single_markers "Modified to detect empty python_version intersections"
Loading

File-Level Changes

Change Details Files
Added tests to verify that the intersection of certain python_version markers is correctly detected as empty.
  • Added a new test case test_single_marker_intersect_is_empty with several scenarios where the intersection of two python_version markers should result in an empty marker.
tests/version/test_markers.py
Modified the _merge_single_markers function to handle cases where the intersection of python_version markers results in an empty marker.
  • Added logic to detect when the intersection of two python_version markers results in an empty constraint.
  • When an empty constraint is detected, the function now returns an EmptyMarker.
src/poetry/core/version/markers.py
Updated existing tests to reflect changes in marker intersection logic.
  • Modified test_intersection_no_endless_recursion to assert the correct marker string representation after intersection.
  • Removed a redundant test case from test_multi_marker_union_multi_is_multi.
tests/version/test_markers.py

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@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 @radoering - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The added tests cover a good range of scenarios for empty marker intersections.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

('python_version == "3.6"', 'python_version == "3.7"'),
('python_version > "3.6"', 'python_version <= "3.6"'),
('python_version >= "3.6"', 'python_version < "3.6"'),
('python_version > "3.6"', 'python_version < "3.7"'),
Copy link
Member Author

Choose a reason for hiding this comment

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

The last test is the relevant one but since I did not find such a basic test function that tests for empty single marker intersections, I just added some additional tests.

Comment on lines -855 to -859
(
'python_version > "3.6" and python_full_version < "3.6.2"',
'python_version > "3.6" and python_version < "3.7"',
'python_version > "3.6" and python_version < "3.7"',
),
Copy link
Member Author

Choose a reason for hiding this comment

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

The test does not make sense because both markers are empty. Similar (but correct) tests are above and below.

@@ -2260,16 +2271,16 @@ def test_intersection_no_endless_recursion() -> None:
' and extra != "postgis"'
)
m2 = parse_marker(
'python_version > "3.12" and python_version < "3.13" or extra != "databricks"'
'python_version >= "3.12" and python_version < "3.13" or extra != "databricks"'
Copy link
Member Author

@radoering radoering Mar 8, 2025

Choose a reason for hiding this comment

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

The original marker is actually empty and does not trigger a potential endless recursion anymore. I checked that the changed marker triggers the recursion error without the fix from #832.

@radoering radoering requested a review from a team March 8, 2025 12:31
Without this fix, the intersection of `python_version > "3.8"` and `python_version < "3.9"` is not detected as empty marker.
@radoering radoering force-pushed the fix-python-version-empty-marker branch from 2676413 to 8a95477 Compare March 11, 2025 13:33
@radoering radoering enabled auto-merge (squash) March 11, 2025 13:34
@radoering radoering merged commit 38ecbbf into python-poetry:main Mar 11, 2025
18 checks passed
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