Fix mypy and pylint issues introduced by the xtractmime merge

- Add xtractmime to the mypy ignore_missing_imports overrides (no py.typed
  marker in that library)
- Narrow Content-Disposition header via a local variable so mypy can see
  it is non-None inside the if-block
- Remove a redundant local re-import of HtmlResponse/TextResponse inside
  open_in_browser (they are already imported at module level, fixing
  pylint W0404 reimported)
- Add Any annotations to _unmark() in test_responsetypes.py so mypy does
  not raise no-untyped-call when it is called from a typed context

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Adrian Chaves 2026-06-10 12:05:07 +02:00
parent 16d4b85caf
commit 82e280dde1
3 changed files with 10 additions and 10 deletions

View File

@ -133,6 +133,8 @@ module = [
"pytest_twisted",
"robotexclusionrulesparser",
"testfixtures",
"xtractmime",
"xtractmime.*",
"zope.interface.*",
]
ignore_missing_imports = true

View File

@ -94,13 +94,10 @@ def _get_encoding_or_mime_type_from_headers(
)
):
return None, headers[b"Content-Type"]
if headers.get(b"Content-Disposition"):
content_disposition = headers.get(b"Content-Disposition")
if content_disposition:
path = (
headers[b"Content-Disposition"]
.split(b";")[-1]
.split(b"=")[-1]
.strip(b"\"'")
.decode()
content_disposition.split(b";")[-1].split(b"=")[-1].strip(b"\"'").decode()
)
encoding, mime_type = _get_encoding_or_mime_type_from_path(path)
if encoding:
@ -262,9 +259,6 @@ def open_in_browser(
if "item name" not in response.body:
open_in_browser(response)
"""
# circular imports
from scrapy.http import HtmlResponse, TextResponse # noqa: PLC0415
# XXX: this implementation is a bit dirty and could be improved
body = response.body
if isinstance(response, HtmlResponse):

View File

@ -1,3 +1,7 @@
from __future__ import annotations
from typing import Any
import pytest
from scrapy.http import (
@ -13,7 +17,7 @@ from scrapy.responsetypes import responsetypes
from .test_utils_response import POST_XTRACTMIME_SCENARIOS, PRE_XTRACTMIME_SCENARIOS
def _unmark(item):
def _unmark(item: Any) -> Any:
return pytest.param(*item.values)