Improve ergonomics of `Requirement.marker` evaluation
Open
Nobody has claimed this yet.
enhancement
packaging.markers
packaging.requirements
- Dominant language
- Python
- Stars
- 751
- Forks
- 324
- Avg merge
- 12h 58m
- Merged PRs (30d)
- 3
Description
Currently Requirement.marker is of type Optional[Marker], and the following code is needed to check whether a requirement needs to be resolved:
def needs_resolution(r: Requirement) -> bool:
if not r.marker:
return True
return r.marker.evaluate()
which becomes cumbersome quickly. I can think of three ways to improve the interface:
- Allow
Marker('')that always evaluate to True (similar toSpecifierSet('')), and use that to indicate no markers instead ofNone. This could be a problem if people are checking formarker is None, but I think most of the use cases should also be compatible withevaluate(). - Similar to 2., but do this with another class
EmptyMarker. This has most of the same problems as above, and may also be a problem for people doingisinstance(marker, Marker). Maybe this can be worked around with__subclasscheck__? - Introduce a convinience method
Requirement.evaluate_marker()that encapsulate the above logic. This is the least disruptive change, but could be a bit confusing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Requirement.marker and Marker.evaluate interfaces described in the issue. Compare the three proposed approaches, including their effects on None checks, isinstance checks, and backwards compatibility. Done when one interface direction is selected and its expected behavior is clearly specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100