Fix TypeError with Click Sentinel in Python 3.14 #723
Merged
+2
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix TypeError with Click Sentinel in Python 3.14
Closes #722
Problem
When running pytask 0.5.6 with Python 3.14 and Click 8.3.1, users encounter:
This occurs during dependency resolution when no
-kor-mflags are provided.Root Cause
In Click 8.3.1, when a
click.Optiondoesn't have an explicitdefaultparameter, it usesSentinel.UNSET(an enum) instead ofNone.The code path:
session.config["expression"]retrievesSentinel.UNSETwhen no-kflag is givenselect_by_keyword()passes this toExpression.compile_(keywordexpr)Scanner.lex()tries to calllen(input_)on the Sentinellen()Stack trace shows error at:
Solution
Add explicit
default=Noneto both click.Option definitions insrc/_pytask/mark/__init__.py:-m/--marker_expression-k/--expressionThe existing
if not keywordexpr:checks (lines 157, 212) already handleNonecorrectly.Changes
src/_pytask/mark/__init__.py: Addeddefault=Noneto two click.Option definitionsTesting
Tested with:
Before fix:
After fix:
Also verified:
-k expressionflag works correctly when provided-m markerflag works correctly when providedCompatibility
This fix maintains backward compatibility while adding support for:
This is my first contribution to pytask. Happy to make any changes you'd like!