Repository navigation
Let the incr and decr stubs accept default=None - #41
Merged
Merged
Conversation
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.
The type stubs reject
default=Noneinincranddecr, which the code has always accepted: withdefault=Nonea missing or expired key raisesKeyErrorinstead of starting from a default.BaseCachein_types.pyitypeddefaultasint, so mypy reports anarg-typeerror on a call such ascache.incr(key, 1, default=None):This showed up when moving ai-marketplace-monitor to 5.8.2: its two counter calls in
utils.pypassdefault=None, and the only way through was# type: ignore[arg-type].BaseCache.incranddecrtakedefault: int | None.CacheandFanoutCacheinherit both and don't redeclare them.DjangoCachealready acceptedNone, and the recipes don't declare either method.tests/typecheck_stubs.pyholds calls that must type-check against the stubs:incranddecrwithdefault=NoneonCacheandFanoutCache.tox -e mypy, and so the CI lint job, now checks it next to the package. pytest doesn't collect it.CHANGELOG.mdentry underUnreleased.The runtime code is unchanged.
Checked:
tox -e mypyfails with the error above on the four new calls against the old stub, and passes here (mypy 2.4.1).bluecheck,flake8,isortcheck,mypyandpylintpass.stubtestreports the same onmasterand on this branch.Possible follow-ups, not in this PR:
FanoutCache.incranddecrreturnNoneon a database timeout, but the stub saysint.incrdocstrings pass a floatdelta, which works at runtime, but the stubs allow onlyint.__init__.pyileaves outDjangoCache, which is exported when Django is installed, sostubtestreports it.stubtestdoesn't run in CI.