From fee2d52f3069a520c61eff72cce6fab722024608 Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Sat, 23 Nov 2024 11:23:13 +0200 Subject: [PATCH] Use PEP 585 type annotations Signed-off-by: Emanuele Giaquinta --- benchmarks/bench_dataclass.py | 3 +-- benchmarks/bench_pydantic.py | 4 +--- tests/test_circular.py | 8 +++----- tests/test_dict.py | 4 +--- tests/test_list.py | 4 +--- tests/test_subclass.py | 7 +++---- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/benchmarks/bench_dataclass.py b/benchmarks/bench_dataclass.py index 6f7c084d..b1890931 100644 --- a/benchmarks/bench_dataclass.py +++ b/benchmarks/bench_dataclass.py @@ -1,5 +1,4 @@ import dataclasses -from typing import List import msgpack @@ -16,7 +15,7 @@ class Member: class Object: id: int name: str - members: List[Member] + members: list[Member] objects_as_dataclass = [ diff --git a/benchmarks/bench_pydantic.py b/benchmarks/bench_pydantic.py index 2aae5c91..f950b33f 100644 --- a/benchmarks/bench_pydantic.py +++ b/benchmarks/bench_pydantic.py @@ -1,5 +1,3 @@ -from typing import List - import msgpack from pydantic import BaseModel @@ -14,7 +12,7 @@ class Member(BaseModel): class Object(BaseModel): id: int name: str - members: List[Member] + members: list[Member] objects_as_pydantic = [ diff --git a/tests/test_circular.py b/tests/test_circular.py index 52231189..41796721 100644 --- a/tests/test_circular.py +++ b/tests/test_circular.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) -from typing import Dict, List - import pytest import ormsgpack @@ -11,7 +9,7 @@ def test_circular_dict() -> None: """ packb() circular reference dict """ - obj: Dict[str, object] = {} + obj: dict[str, object] = {} obj["obj"] = obj with pytest.raises(ormsgpack.MsgpackEncodeError): ormsgpack.packb(obj) @@ -21,7 +19,7 @@ def test_circular_list() -> None: """ packb() circular reference list """ - obj: List[object] = [] + obj: list[object] = [] obj.append(obj) with pytest.raises(ormsgpack.MsgpackEncodeError): ormsgpack.packb(obj) @@ -31,7 +29,7 @@ def test_circular_nested() -> None: """ packb() circular reference nested dict, list """ - obj: Dict[str, object] = {} + obj: dict[str, object] = {} obj["list"] = [{"obj": obj}] with pytest.raises(ormsgpack.MsgpackEncodeError): ormsgpack.packb(obj) diff --git a/tests/test_dict.py b/tests/test_dict.py index f00c07f3..43ecfb25 100644 --- a/tests/test_dict.py +++ b/tests/test_dict.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) -from typing import Dict - import msgpack import pytest @@ -16,7 +14,7 @@ pytest.param({str(i): i for i in range(65536)}, id="map 32"), ), ) -def test_dict(value: Dict[str, int]) -> None: +def test_dict(value: dict[str, int]) -> None: packed = ormsgpack.packb(value) assert packed == msgpack.packb(value) assert ormsgpack.unpackb(packed) == value diff --git a/tests/test_list.py b/tests/test_list.py index 3138d700..8940de67 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -1,7 +1,5 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) -from typing import List - import msgpack import pytest @@ -16,7 +14,7 @@ pytest.param([i for i in range(65536)], id="array 32"), ), ) -def test_list(value: List[int]) -> None: +def test_list(value: list[int]) -> None: packed = ormsgpack.packb(value) assert packed == msgpack.packb(value) assert ormsgpack.unpackb(packed) == value diff --git a/tests/test_subclass.py b/tests/test_subclass.py index 0b09fa1f..35f012e5 100644 --- a/tests/test_subclass.py +++ b/tests/test_subclass.py @@ -1,7 +1,6 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections -from typing import Dict, List, Tuple import msgpack import pytest @@ -17,11 +16,11 @@ class SubInt(int): pass -class SubDict(Dict[str, object]): +class SubDict(dict[str, object]): pass -class SubList(List[object]): +class SubList(list[object]): pass @@ -29,7 +28,7 @@ class SubFloat(float): pass -class SubTuple(Tuple[object, object]): +class SubTuple(tuple[object, object]): pass