Suppress the false type error on assigning a CA bundle to verify - #22
Merged
Conversation
requests documents verify as either a bool or a path to a CA bundle, and passing a path is what tls_cert is for. But requests ships no annotations, so a checker reading its source infers the attribute as bool from `self.verify = True` in Session.__init__, and reports the assignment as a type error: ERROR `str` is not assignable to attribute `verify` with type `bool` Both assignment sites carry the ignore; only the second had been reported. The ignore is bare rather than naming a rule because the name differs between checkers -- assignment for mypy, bad-assignment for ty -- and a code that does not match the checker in use is itself reported as an unused suppression.
tomchop
force-pushed
the
fix/tls-cert-assignment-typing
branch
from
September 3, 2026 07:43
35d4176 to
1c7f0ea
Compare
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.
Reported from a downstream pipeline that type-checks this package's source after vendoring it:
The code is correct
requestsdocuments the field as accepting both:Passing a path is exactly what
tls_certexists for.Why the checker disagrees
requestsships nopy.typedand no annotation on the attribute. A checker reading its source therefore infers the type from the only assignment it can see, inSession.__init__:With
types-requestsstubs it isbool | strand there is no error, which is why this does not reproduce in environments that resolve stubs rather than vendored source.Change
A bare
# type: ignoreon both assignment sites, with a comment recording why the assignment is sound.Both sites —
__init__(line 81) andauth_api_key(line 178). Only the second was reported, but they are the same assignment and the first would surface as soon as that code path is reached by the same analysis.Bare rather than coded because the rule name differs per checker —
assignmentfor mypy,bad-assignmentfor ty,reportAttributeAccessIssuefor pyright — and a code that does not match the checker in use is itself flagged as an unused suppression. A bare ignore is honoured by all three.Tests
31 passing, unchanged. This repository has no type-check job of its own, which is why the error only surfaced downstream.