-
Notifications
You must be signed in to change notification settings - Fork 255
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
fix endless recursion introduced in #821 #832
fix endless recursion introduced in #821 #832
Conversation
Reviewer's Guide by SourceryThis pull request addresses an endless recursion issue introduced in #821. The fix involves adding a decorator to detect recursion in the Sequence diagram for marker intersection with recursion detectionsequenceDiagram
participant Client
participant intersection
participant detect_recursion
participant cnf
Client->>intersection: intersection(*markers)
activate intersection
intersection->>detect_recursion: Check recursion
activate detect_recursion
alt No recursion detected
detect_recursion-->>intersection: Continue
intersection->>cnf: Convert to CNF
alt CNF successful
cnf-->>intersection: Return conjunction
intersection->>intersection: Select min complexity
else RecursionError
cnf-->>intersection: Throw RecursionError
intersection->>intersection: Use limited candidates
end
else Recursion detected
detect_recursion-->>intersection: Throw RecursionError
end
intersection-->>Client: Return marker
deactivate intersection
deactivate detect_recursion
Class diagram for marker system with recursion detectionclassDiagram
class BaseMarker {
+complexity
}
class MarkerUnion {
+markers
}
class MultiMarker {
+markers
}
class detect_recursion {
+call_args: dict
+decorated(*markers): BaseMarker
}
BaseMarker <|-- MarkerUnion
BaseMarker <|-- MultiMarker
note for detect_recursion "Decorator to detect recursions
in intersection and union"
detect_recursion ..> BaseMarker: decorates
Flow diagram for marker processing with recursion handlingflowchart TD
A[Start] --> B{Check recursion}
B -->|No recursion| C[Process markers]
B -->|Recursion detected| D[Throw RecursionError]
C --> E{Try normalization}
E -->|Success| F[Select min complexity]
E -->|RecursionError| G[Use limited candidates]
F --> H[Return result]
G --> H
D --> I[Handle in caller]
I --> J[Use unnormalized form]
J --> H
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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:
- Please update the documentation to mention the recursion detection behavior in intersection/union operations, as indicated in the PR checklist.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟡 Security: 1 issue found
- 🟡 Testing: 1 issue found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/poetry/core/version/markers.py
Outdated
if markers in call_args: | ||
raise RecursionError | ||
call_args.append(markers) | ||
result = func(*markers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Call stack cleanup should be guaranteed even if an exception occurs
Wrap the function call in a try-finally block to ensure call_args.pop() is always executed, even when exceptions occur.
b44d832
to
588afc4
Compare
Related to python-poetry/poetry#9956 (comment)
Previously, we have always tried to avoid recursions, which is difficult if you do not want to miss any simplifications. Although, #821 provides significant performance improvements for certain cases, it also introduces the risk of endless recursions due to the symmetry of
intersection
andunion
. It might still be possible to avoid this recursion with a more sophisticated fix. However, I decided to detect a recursion early instead of avoiding it.Summary by Sourcery
Bug Fixes: