{{ message }}
Repository navigation
Fix false positive for sentinel calls with a repr argument - #11896
Open
crypt0lith wants to merge 1 commit into
Open
crypt0lith wants to merge 1 commit into
crypt0lith wants to merge 1 commit into
Conversation
createSentinelType rejects any call with more than one argument, so passing the keyword-only repr parameter of sentinel reports an error and evaluates the sentinel to Never. Require exactly one positional argument, accept a repr keyword argument, and check its type against 'str | None'. Drop the typing_extensions.Sentinel check, which the stub now aliases to sentinel. Fixes microsoft#11893
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Fixes #11893
Passing
repr=tosentinelortyping_extensions.Sentinelreports a falsereportCallIssueerror. The sentinel then evaluates toNeverand can't be used in type expressions.Root cause
createSentinelTypereportssentinelParamCountfor any call whose argument list doesn't have exactly one entry. Both stubs declare a keyword-onlyrepr: str | Noneparameter after the positionalname, so a validreprargument fails the check. The function then returnsundefinedinstead of the sentinel type.Fix
Require exactly one positional argument, and allow
repras the only keyword argument. Report any other argument as before, and report areprvalue not assignable tostr | NoneunderreportArgumentType. Drop thetyping_extensions.Sentineldispatch check, since the stub now definesSentinelas an alias ofsentinel.Test
Remove
sentinel2.py. Since #11727,typing_extensions.sentinelresolves tobuiltins.sentinelon 3.15, and every check insentinel2.pyalready exists insentinel1.py. Switchsentinel1.pyfrom theSentinelalias tosentinel.Cases added to
sentinel1.pyBAD_CALL4reprvalue notstr | NoneBAD_CALL5BAD_CALL6reprREPR1reprkeyword: sentinel type, usable in a union annotation and narrowed byis