diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8dc94e9f..5e4db59a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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' diff --git a/pyproject.toml b/pyproject.toml index d920387f..985fd180 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ strict = true show_error_codes = true enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unused_ignores = true +python_version = 3.8 [[tool.mypy.overrides]] module = ["_manylinux"] diff --git a/src/packaging/metadata.py b/src/packaging/metadata.py index 1316e78b..721f411c 100644 --- a/src/packaging/metadata.py +++ b/src/packaging/metadata.py @@ -1,12 +1,12 @@ from __future__ import annotations -import builtins import email.feedparser import email.header import email.message import email.parser import email.policy import pathlib +import sys import typing from typing import ( Any, @@ -24,7 +24,7 @@ T = typing.TypeVar("T") -if "ExceptionGroup" in builtins.__dict__: # pragma: no cover +if sys.version_info >= (3, 11): # pragma: no cover ExceptionGroup = ExceptionGroup else: # pragma: no cover @@ -222,12 +222,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: @@ -434,7 +436,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: diff --git a/src/packaging/tags.py b/src/packaging/tags.py index 977cc122..f5903402 100644 --- a/src/packaging/tags.py +++ b/src/packaging/tags.py @@ -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() # type: ignore[attr-defined, unused-ignore] version = cast("AppleVersion", tuple(map(int, release.split(".")[:2]))) if multiarch is None: diff --git a/src/packaging/version.py b/src/packaging/version.py index edee1004..233dd4d0 100644 --- a/src/packaging/version.py +++ b/src/packaging/version.py @@ -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"