From 40b71bbba4d356d9331b9d3355d2f7dc0af8e960 Mon Sep 17 00:00:00 2001 From: Eirini Galati Date: Sun, 1 Nov 2026 00:18:30 +0100 Subject: [PATCH] fix: repair the mypy CI step The Mypy job has been failing on every branch: mypy: error: ambiguous option: --check could match --check-untyped-defs, --check-unreachable --check was never a real flag. It used to resolve as an unambiguous abbreviation, but a newer mypy added --check-unreachable, so it no longer does and mypy exits 2 during argument parsing, before reading any source. setup.py lists mypy unpinned, so CI installs whatever is current. Dropping the flag exposed a second, pre-existing error that had been masked for as long as the step was broken: tinify/client.py:34: Incompatible types in assignment (expression has type "dict[str, str]", variable has type "CaseInsensitiveDict[str]") requests types Session.headers as CaseInsensitiveDict, so wrap the literal rather than assigning a plain dict. This is what requests builds the attribute with by default, so runtime behaviour is unchanged and header lookups become case-insensitive as the library intends. mypy tinify now reports no issues across all 8 source files. --- .github/workflows/ci-cd.yml | 2 +- tinify/client.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 76b4b5d..4735108 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -50,7 +50,7 @@ jobs: pip install -r test-requirements.txt -r requirements.txt - name: Run tests run: | - mypy --check tinify + mypy tinify Integration_tests: if: github.event_name == 'push' diff --git a/tinify/client.py b/tinify/client.py index a170b05..ae27548 100644 --- a/tinify/client.py +++ b/tinify/client.py @@ -5,6 +5,7 @@ import os import platform import requests +from requests.structures import CaseInsensitiveDict import requests.exceptions from requests.compat import json # type: ignore import traceback @@ -31,9 +32,9 @@ def __init__(self, key, app_identifier=None, proxy=None): # type: (str, Optiona if proxy: self.session.proxies = {'https': proxy} self.session.auth = ('api', key) - self.session.headers = { + self.session.headers = CaseInsensitiveDict({ 'user-agent': self.USER_AGENT + ' ' + app_identifier if app_identifier else self.USER_AGENT, - } + }) self.session.verify = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'cacert.pem') def __enter__(self): # type: () -> Client