Skip to content

Commit

Permalink
Upgrade to latest mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Nov 3, 2024
1 parent d1a9f93 commit bd71ca6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.13.0
hooks:
- id: mypy
exclude: '^(docs|tasks|tests)|setup\.py'
Expand Down
11 changes: 7 additions & 4 deletions src/packaging/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pathlib
import typing
from typing import (
TYPE_CHECKING,
Any,
Callable,
Generic,
Expand All @@ -26,7 +27,7 @@

if "ExceptionGroup" in builtins.__dict__: # pragma: no cover
ExceptionGroup = ExceptionGroup
else: # pragma: no cover
elif not TYPE_CHECKING: # pragma: no cover

class ExceptionGroup(Exception):
"""A minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.
Expand Down Expand Up @@ -222,12 +223,14 @@ def _get_payload(msg: email.message.Message, source: bytes | str) -> str:
# If our source is a str, then our caller has managed encodings for us,
# and we don't need to deal with it.
if isinstance(source, str):
payload: str = msg.get_payload()
payload = msg.get_payload()
assert isinstance(payload, str)
return payload
# If our source is a bytes, then we're managing the encoding and we need
# to deal with it.
else:
bpayload: bytes = msg.get_payload(decode=True)
bpayload = msg.get_payload(decode=True)
assert isinstance(bpayload, bytes)
try:
return bpayload.decode("utf8", "strict")
except UnicodeDecodeError as exc:
Expand Down Expand Up @@ -434,7 +437,7 @@ def parse_email(data: bytes | str) -> tuple[RawMetadata, dict[str, list[str]]]:
payload = _get_payload(parsed, data)
except ValueError:
unparsed.setdefault("description", []).append(
parsed.get_payload(decode=isinstance(data, bytes))
parsed.get_payload(decode=isinstance(data, bytes)) # type: ignore[call-overload]
)
else:
if payload:
Expand Down
2 changes: 1 addition & 1 deletion src/packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def ios_platforms(
# if iOS is the current platform, ios_ver *must* be defined. However,
# it won't exist for CPython versions before 3.13, which causes a mypy
# error.
_, release, _, _ = platform.ios_ver() # type: ignore[attr-defined]
_, release, _, _ = platform.ios_ver()
version = cast("AppleVersion", tuple(map(int, release.split(".")[:2])))

if multiarch is None:
Expand Down
4 changes: 3 additions & 1 deletion src/packaging/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ def _parse_letter_version(
letter = "post"

return letter, int(number)
if not letter and number:

assert not letter
if number:
# We assume if we are given a number, but we are not given a letter
# then this is using the implicit post release syntax (e.g. 1.0-1)
letter = "post"
Expand Down

0 comments on commit bd71ca6

Please # to comment.