Fixed crash in protocol check when subject method has no positional params#551
Merged
agronholm merged 4 commits intoagronholm:masterfrom May 1, 2026
Merged
Conversation
Owner
|
You checked the checkbox for adding a new changelog entry when you clearly haven't done so. What gives? |
Contributor
Author
|
Fixed |
Owner
|
Thanks! |
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.
Changes
Fixes #550
check_signature_compatibleinsrc/typeguard/_checkers.pycalls.pop(0)onprotocol_argsandsubject_argsto strip the implicitself, but does so unconditionally whenever the corresponding side is classified as"instance". If the subject method'sinspect.signature(...)reports zero positional-or-keyword parameters and no*args(e.g. a callable instance assigned at class scope, afunctools.partialwith all positional args bound, or a method proxied by a code-generation framework),subject_argsis empty andpop(0)raisesIndexErrorinstead of letting the function fall through to its existingzip_longestcomparison and emit aTypeCheckError.This guards each pop with a non-empty check. After the change, the previously-crashing input raises
TypeCheckError("... has too few positional arguments")along the same path as the equivalent N → N-1 mismatch with one more arg, restoringcheck_type's documented contract that callers can catch viaexcept TypeCheckError.Regression test added under
tests/test_checkers.py::TestProtocol::test_subject_method_no_positional_params.Checklist
If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):
tests/) added which would fail without your patchdocs/, in case of behavior changes or newfeatures)
docs/versionhistory.rst).If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.
Updating the changelog
#550 <https://github.com/agronholm/typeguard/issues/550>_; PR by @HackedRico)