Skip to content

Commit 4dc334c

Browse files
authored
Upgrade to latest mypy (#853)
1 parent d1a9f93 commit 4dc334c

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- id: trailing-whitespace
99

1010
- repo: https://github.com/pre-commit/mirrors-mypy
11-
rev: v0.991
11+
rev: v1.13.0
1212
hooks:
1313
- id: mypy
1414
exclude: '^(docs|tasks|tests)|setup\.py'

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ strict = true
5252
show_error_codes = true
5353
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
5454
warn_unused_ignores = true
55+
python_version = 3.8
5556

5657
[[tool.mypy.overrides]]
5758
module = ["_manylinux"]

src/packaging/metadata.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

3-
import builtins
43
import email.feedparser
54
import email.header
65
import email.message
76
import email.parser
87
import email.policy
98
import pathlib
9+
import sys
1010
import typing
1111
from typing import (
1212
Any,
@@ -24,7 +24,7 @@
2424
T = typing.TypeVar("T")
2525

2626

27-
if "ExceptionGroup" in builtins.__dict__: # pragma: no cover
27+
if sys.version_info >= (3, 11): # pragma: no cover
2828
ExceptionGroup = ExceptionGroup
2929
else: # pragma: no cover
3030

@@ -222,12 +222,14 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
222222
# If our source is a str, then our caller has managed encodings for us,
223223
# and we don't need to deal with it.
224224
if isinstance(source, str):
225-
payload: str = msg.get_payload()
225+
payload = msg.get_payload()
226+
assert isinstance(payload, str)
226227
return payload
227228
# If our source is a bytes, then we're managing the encoding and we need
228229
# to deal with it.
229230
else:
230-
bpayload: bytes = msg.get_payload(decode=True)
231+
bpayload = msg.get_payload(decode=True)
232+
assert isinstance(bpayload, bytes)
231233
try:
232234
return bpayload.decode("utf8", "strict")
233235
except UnicodeDecodeError as exc:
@@ -434,7 +436,7 @@ def parse_email(data: bytes | str) -> tuple[RawMetadata, dict[str, list[str]]]:
434436
payload = _get_payload(parsed, data)
435437
except ValueError:
436438
unparsed.setdefault("description", []).append(
437-
parsed.get_payload(decode=isinstance(data, bytes))
439+
parsed.get_payload(decode=isinstance(data, bytes)) # type: ignore[call-overload]
438440
)
439441
else:
440442
if payload:

src/packaging/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def ios_platforms(
490490
# if iOS is the current platform, ios_ver *must* be defined. However,
491491
# it won't exist for CPython versions before 3.13, which causes a mypy
492492
# error.
493-
_, release, _, _ = platform.ios_ver() # type: ignore[attr-defined]
493+
_, release, _, _ = platform.ios_ver() # type: ignore[attr-defined, unused-ignore]
494494
version = cast("AppleVersion", tuple(map(int, release.split(".")[:2])))
495495

496496
if multiarch is None:

src/packaging/version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,9 @@ def _parse_letter_version(
493493
letter = "post"
494494

495495
return letter, int(number)
496-
if not letter and number:
496+
497+
assert not letter
498+
if number:
497499
# We assume if we are given a number, but we are not given a letter
498500
# then this is using the implicit post release syntax (e.g. 1.0-1)
499501
letter = "post"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy