From 2b08129a1952e54d72b14d67c2865ee93f48c2b3 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Mon, 14 Oct 2024 13:57:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Prepare=20for=20Python=203?= =?UTF-8?q?.14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #177 --- pure_protobuf/descriptors/record.py | 11 ++++++++--- pyproject.toml | 4 +--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pure_protobuf/descriptors/record.py b/pure_protobuf/descriptors/record.py index eda3322..245c72f 100644 --- a/pure_protobuf/descriptors/record.py +++ b/pure_protobuf/descriptors/record.py @@ -1,6 +1,5 @@ from __future__ import annotations -from collections.abc import ByteString, Mapping from dataclasses import dataclass from enum import IntEnum from types import GenericAlias @@ -71,7 +70,7 @@ class RecordDescriptor(Generic[RecordT]): merge: Merge[RecordT] = MergeLastOneWins() """Merge two values of the same field from different messages. Only called in a message merger.""" - __PREDEFINED__: ClassVar[Mapping[Any, RecordDescriptor]] + __PREDEFINED__: ClassVar[dict[Any, RecordDescriptor]] """Pre-defined descriptors for primitive types.""" @classmethod @@ -176,7 +175,6 @@ def _from_inner_type_hint( bool: BOOL_DESCRIPTOR, bytes: BYTES_DESCRIPTOR, bytearray: BYTES_DESCRIPTOR, - ByteString: BYTES_DESCRIPTOR, fixed32: UNSIGNED_INT32_DESCRIPTOR, fixed64: UNSIGNED_INT64_DESCRIPTOR, float: FLOAT_DESCRIPTOR, @@ -206,3 +204,10 @@ def _from_inner_type_hint( read=ReadMaybePacked[int](ReadCallback(ReadZigZagVarint()), WireType.VARINT), ), } + +try: + from collections.abc import ByteString +except ImportError: + pass +else: + RecordDescriptor.__PREDEFINED__[ByteString] = BYTES_DESCRIPTOR diff --git a/pyproject.toml b/pyproject.toml index 604e4e1..c0c6fe7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,7 @@ exclude_lines = [ [tool.black] line-length = 120 -target-version = ["py39", "py310", "py311", "py312", "py313"] +target-version = ["py39", "py310", "py311", "py312", "py313", "py314"] [tool.ruff] line-length = 120 @@ -148,9 +148,7 @@ ignore = [ "PT013", "RET505", "TRY003", - "UP006", # 3.9 "UP007", # 3.10 - "UP033", # 3.9 ] [tool.ruff.lint.per-file-ignores]