1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-11 14:51:32 +00:00

Bump mypy and stubs.

This commit is contained in:
Andrey Rakhmatullin 2024-12-29 16:45:26 +05:00
parent 4a0c05749c
commit f7af7b282d
5 changed files with 19 additions and 16 deletions

View File

@ -131,25 +131,26 @@ class CookiesMiddleware:
decoded = {}
flags = set()
for key in ("name", "value", "path", "domain"):
if cookie.get(key) is None:
value = cookie.get(key)
if value is None:
if key in ("name", "value"):
msg = f"Invalid cookie found in request {request}: {cookie} ('{key}' is missing)"
logger.warning(msg)
return None
continue
# https://github.com/python/mypy/issues/7178, https://github.com/python/mypy/issues/9168
if isinstance(cookie[key], (bool, float, int, str)): # type: ignore[literal-required]
decoded[key] = str(cookie[key]) # type: ignore[literal-required]
if isinstance(value, (bool, float, int, str)):
decoded[key] = str(value)
else:
assert isinstance(value, bytes)
try:
decoded[key] = cookie[key].decode("utf8") # type: ignore[literal-required]
decoded[key] = value.decode("utf8")
except UnicodeDecodeError:
logger.warning(
"Non UTF-8 encoded cookie found in request %s: %s",
request,
cookie,
)
decoded[key] = cookie[key].decode("latin1", errors="replace") # type: ignore[literal-required]
decoded[key] = value.decode("latin1", errors="replace")
for flag in ("secure",):
value = cookie.get(flag, _UNSET)
if value is _UNSET or not value:

View File

@ -75,7 +75,7 @@ class TelnetConsole(protocol.ServerFactory):
def stop_listening(self) -> None:
self.port.stopListening()
def protocol(self) -> telnet.TelnetTransport: # type: ignore[override]
def protocol(self) -> telnet.TelnetTransport:
# these import twisted.internet.reactor
from twisted.conch import manhole, telnet
from twisted.conch.insults import insults

View File

@ -44,10 +44,10 @@ if TYPE_CHECKING:
class VerboseCookie(TypedDict):
name: str
value: str
domain: NotRequired[str]
path: NotRequired[str]
name: str | bytes
value: str | bytes | bool | float | int
domain: NotRequired[str | bytes]
path: NotRequired[str | bytes]
secure: NotRequired[bool]

View File

@ -26,13 +26,15 @@ class Sitemap:
)
self._root = lxml.etree.fromstring(xmltext, parser=xmlp) # noqa: S320
rt = self._root.tag
self.type = self._root.tag.split("}", 1)[1] if "}" in rt else rt
assert isinstance(rt, str)
self.type = rt.split("}", 1)[1] if "}" in rt else rt
def __iter__(self) -> Iterator[dict[str, Any]]:
for elem in self._root.getchildren():
d: dict[str, Any] = {}
for el in elem.getchildren():
tag = el.tag
assert isinstance(tag, str)
name = tag.split("}", 1)[1] if "}" in tag else tag
if name == "link":

View File

@ -43,12 +43,12 @@ install_command =
[testenv:typing]
basepython = python3
deps =
mypy==1.12.0
mypy==1.14.0
typing-extensions==4.12.2
types-lxml==2024.9.16
types-lxml==2024.12.13
types-Pygments==2.18.0.20240506
botocore-stubs==1.35.39
boto3-stubs[s3]==1.35.39
botocore-stubs==1.35.90
boto3-stubs[s3]==1.35.90
attrs >= 18.2.0
Pillow >= 10.3.0
pyOpenSSL >= 24.2.1