Skip to content

Suppress the false type error on assigning a CA bundle to verify - #22

Merged
tomchop merged 1 commit into
mainfrom
fix/tls-cert-assignment-typing
Sep 3, 2026
Merged

Suppress the false type error on assigning a CA bundle to verify#22
tomchop merged 1 commit into
mainfrom
fix/tls-cert-assignment-typing

Conversation

@tomchop

@tomchop tomchop commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Reported from a downstream pipeline that type-checks this package's source after vendoring it:

ERROR `str` is not assignable to attribute `verify` with type `bool` [bad-assignment]
   --> third_party/py/yeti/api.py:178:36
    |
178 |             authd_session.verify = self._tls_cert

The code is correct

requests documents the field as accepting both:

verify – (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use.

Passing a path is exactly what tls_cert exists for.

Why the checker disagrees

requests ships no py.typed and no annotation on the attribute. A checker reading its source therefore infers the type from the only assignment it can see, in Session.__init__:

self.verify = True      # -> inferred as bool

With types-requests stubs it is bool | str and there is no error, which is why this does not reproduce in environments that resolve stubs rather than vendored source.

Change

A bare # type: ignore on both assignment sites, with a comment recording why the assignment is sound.

Both sites__init__ (line 81) and auth_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 — assignment for mypy, bad-assignment for ty, reportAttributeAccessIssue for 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.

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
tomchop force-pushed the fix/tls-cert-assignment-typing branch from 35d4176 to 1c7f0ea Compare September 3, 2026 07:43
@tomchop
tomchop merged commit 3ea3797 into main Sep 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant