diff --git a/benchmarks/bench_encodings.py b/benchmarks/bench_encodings.py index a07b7e7c..8360afb7 100644 --- a/benchmarks/bench_encodings.py +++ b/benchmarks/bench_encodings.py @@ -1,16 +1,16 @@ from __future__ import annotations -import sys import dataclasses +import importlib.metadata import json +import sys import timeit -import importlib.metadata -from typing import Any, Literal, Callable - -from .generate_data import make_filesystem_data +from typing import Any, Callable, Literal import msgspec +from .generate_data import make_filesystem_data + class File(msgspec.Struct, kw_only=True, omit_defaults=True, tag="file"): name: str @@ -61,9 +61,9 @@ def run(self, data: bytes) -> dict: def json_benchmarks(): import orjson - import ujson import rapidjson import simdjson + import ujson simdjson_ver = importlib.metadata.version("pysimdjson") diff --git a/benchmarks/bench_structs.py b/benchmarks/bench_structs.py index 2d5f4d6f..04a21404 100644 --- a/benchmarks/bench_structs.py +++ b/benchmarks/bench_structs.py @@ -217,8 +217,8 @@ def main(): args = parser.parse_args() if args.versions: - import sys import importlib.metadata + import sys for _, lib, _ in BENCHMARKS: if lib is not None: diff --git a/benchmarks/bench_validation/__main__.py b/benchmarks/bench_validation/__main__.py index 5cc11789..4b2ede7b 100644 --- a/benchmarks/bench_validation/__main__.py +++ b/benchmarks/bench_validation/__main__.py @@ -1,11 +1,11 @@ import argparse import json -import tempfile -from ..generate_data import make_filesystem_data -import sys -import subprocess import shutil +import subprocess +import sys +import tempfile +from ..generate_data import make_filesystem_data LIBRARIES = ["msgspec", "mashumaro", "cattrs", "pydantic"] diff --git a/benchmarks/bench_validation/bench_cattrs.py b/benchmarks/bench_validation/bench_cattrs.py index 83d3504b..9c212d99 100644 --- a/benchmarks/bench_validation/bench_cattrs.py +++ b/benchmarks/bench_validation/bench_cattrs.py @@ -1,7 +1,7 @@ from __future__ import annotations -import enum import datetime +import enum from typing import Literal import attrs diff --git a/benchmarks/bench_validation/bench_mashumaro.py b/benchmarks/bench_validation/bench_mashumaro.py index 6a0118af..b128ecc6 100644 --- a/benchmarks/bench_validation/bench_mashumaro.py +++ b/benchmarks/bench_validation/bench_mashumaro.py @@ -1,8 +1,8 @@ from __future__ import annotations -import enum import dataclasses import datetime +import enum from typing import Literal from mashumaro.mixins.orjson import DataClassORJSONMixin diff --git a/benchmarks/bench_validation/bench_msgspec.py b/benchmarks/bench_validation/bench_msgspec.py index f2b3af73..9adc3b1e 100644 --- a/benchmarks/bench_validation/bench_msgspec.py +++ b/benchmarks/bench_validation/bench_msgspec.py @@ -1,7 +1,7 @@ from __future__ import annotations -import enum import datetime +import enum import msgspec diff --git a/benchmarks/bench_validation/bench_pydantic.py b/benchmarks/bench_validation/bench_pydantic.py index 72dd6064..300456c9 100644 --- a/benchmarks/bench_validation/bench_pydantic.py +++ b/benchmarks/bench_validation/bench_pydantic.py @@ -1,8 +1,8 @@ from __future__ import annotations -import enum import datetime -from typing import Literal, Annotated +import enum +from typing import Annotated, Literal import pydantic diff --git a/benchmarks/bench_validation/runner.py b/benchmarks/bench_validation/runner.py index 6d240d5a..5dac94a6 100644 --- a/benchmarks/bench_validation/runner.py +++ b/benchmarks/bench_validation/runner.py @@ -1,9 +1,9 @@ +import gc import importlib import json -import timeit import resource import sys -import gc +import timeit library, path, runs, repeats = sys.argv[1:5] num_runs = int(runs) diff --git a/pyproject.toml b/pyproject.toml index 6e724fe6..a07b09c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -170,6 +170,7 @@ ignore = [ select = [ "E", # PEP8 Errors "F", # Pyflakes + "I", # Import sorting "W", # PEP8 Warnings ] diff --git a/setup.py b/setup.py index 103a074c..22fcbef8 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ -import sys import os +import sys from setuptools import setup from setuptools.extension import Extension diff --git a/src/msgspec/_json_schema.py b/src/msgspec/_json_schema.py index be506e3f..23b45c87 100644 --- a/src/msgspec/_json_schema.py +++ b/src/msgspec/_json_schema.py @@ -3,7 +3,7 @@ import re import textwrap from collections.abc import Iterable -from typing import Any, Optional, Callable +from typing import Any, Callable, Optional from . import inspect as mi, to_builtins diff --git a/src/msgspec/_utils.py b/src/msgspec/_utils.py index 665c5c1f..4c805359 100644 --- a/src/msgspec/_utils.py +++ b/src/msgspec/_utils.py @@ -2,7 +2,6 @@ import collections import sys import typing - from typing import _AnnotatedAlias # noqa: F401 try: diff --git a/src/msgspec/structs.py b/src/msgspec/structs.py index 76f2fdfe..6a4ff765 100644 --- a/src/msgspec/structs.py +++ b/src/msgspec/structs.py @@ -8,8 +8,8 @@ StructConfig, asdict, astuple, - replace, force_setattr, + replace, ) from ._utils import get_class_annotations as _get_class_annotations diff --git a/src/msgspec/toml.py b/src/msgspec/toml.py index c4306440..802bfce4 100644 --- a/src/msgspec/toml.py +++ b/src/msgspec/toml.py @@ -1,7 +1,7 @@ from __future__ import annotations import datetime as _datetime -from typing import TYPE_CHECKING, overload, TypeVar, Any +from typing import TYPE_CHECKING, Any, TypeVar, overload from . import ( DecodeError as _DecodeError, @@ -10,7 +10,8 @@ ) if TYPE_CHECKING: - from typing import Callable, Optional, Type, Union, Literal + from typing import Callable, Literal, Optional, Type, Union + from typing_extensions import Buffer diff --git a/src/msgspec/yaml.py b/src/msgspec/yaml.py index e8f6abc5..d9942290 100644 --- a/src/msgspec/yaml.py +++ b/src/msgspec/yaml.py @@ -1,7 +1,7 @@ from __future__ import annotations import datetime as _datetime -from typing import TYPE_CHECKING, overload, TypeVar, Any +from typing import TYPE_CHECKING, Any, TypeVar, overload from . import ( DecodeError as _DecodeError, @@ -10,7 +10,8 @@ ) if TYPE_CHECKING: - from typing import Callable, Optional, Type, Union, Literal + from typing import Callable, Literal, Optional, Type, Union + from typing_extensions import Buffer diff --git a/tests/unit/test_common.py b/tests/unit/test_common.py index cc005f43..956c0d3a 100644 --- a/tests/unit/test_common.py +++ b/tests/unit/test_common.py @@ -32,7 +32,8 @@ ) import pytest -from .utils import temp_module, max_call_depth + +from .utils import max_call_depth, temp_module try: import attrs @@ -40,7 +41,7 @@ attrs = None import msgspec -from msgspec import Meta, Struct, ValidationError, UNSET, UnsetType +from msgspec import UNSET, Meta, Struct, UnsetType, ValidationError UTC = datetime.timezone.utc diff --git a/tests/unit/test_constraints.py b/tests/unit/test_constraints.py index b85bc999..c9b60b1d 100644 --- a/tests/unit/test_constraints.py +++ b/tests/unit/test_constraints.py @@ -1,7 +1,7 @@ import datetime import math import re -from typing import Dict, List, Union, Annotated +from typing import Annotated, Dict, List, Union import pytest diff --git a/tests/unit/test_convert.py b/tests/unit/test_convert.py index 0b5b18f1..a3cef2c6 100644 --- a/tests/unit/test_convert.py +++ b/tests/unit/test_convert.py @@ -19,17 +19,18 @@ NamedTuple, Set, Tuple, - TypeVar, TypedDict, + TypeVar, Union, ) import pytest -from .utils import temp_module, max_call_depth import msgspec from msgspec import Meta, Struct, ValidationError, convert, to_builtins +from .utils import max_call_depth, temp_module + try: import attrs except ImportError: diff --git a/tests/unit/test_inspect.py b/tests/unit/test_inspect.py index 5de20ac2..08b46c5c 100644 --- a/tests/unit/test_inspect.py +++ b/tests/unit/test_inspect.py @@ -27,12 +27,12 @@ ) import pytest -from .utils import temp_module import msgspec import msgspec.inspect as mi from msgspec import Meta +from .utils import temp_module PY312 = sys.version_info[:2] >= (3, 12) py312_plus = pytest.mark.skipif(not PY312, reason="3.12+ only") diff --git a/tests/unit/test_schema.py b/tests/unit/test_schema.py index 1fd77e72..8a4011a4 100644 --- a/tests/unit/test_schema.py +++ b/tests/unit/test_schema.py @@ -24,11 +24,11 @@ ) import pytest -from .utils import temp_module import msgspec from msgspec import Meta +from .utils import temp_module T = TypeVar("T") diff --git a/tests/unit/test_struct.py b/tests/unit/test_struct.py index 69a89235..1769bb18 100644 --- a/tests/unit/test_struct.py +++ b/tests/unit/test_struct.py @@ -8,15 +8,16 @@ import weakref from contextlib import contextmanager from inspect import Parameter, Signature -from typing import Any, List, Optional, Generic, TypeVar +from typing import Any, Generic, List, Optional, TypeVar import pytest -from .utils import temp_module import msgspec from msgspec import NODEFAULT, UNSET, Struct, defstruct, field from msgspec.structs import StructConfig +from .utils import temp_module + if hasattr(copy, "replace"): # Added in Python 3.13 copy_replace = copy.replace diff --git a/tests/unit/test_struct_meta.py b/tests/unit/test_struct_meta.py index ebd9b0b1..f1714881 100644 --- a/tests/unit/test_struct_meta.py +++ b/tests/unit/test_struct_meta.py @@ -1,9 +1,10 @@ """Tests for the exposed StructMeta metaclass.""" import pytest + import msgspec from msgspec import Struct, StructMeta -from msgspec.structs import asdict, astuple, replace, force_setattr +from msgspec.structs import asdict, astuple, force_setattr, replace def test_struct_meta_exists(): diff --git a/tests/unit/test_to_builtins.py b/tests/unit/test_to_builtins.py index e9f94cc9..29f0240b 100644 --- a/tests/unit/test_to_builtins.py +++ b/tests/unit/test_to_builtins.py @@ -11,7 +11,7 @@ import pytest -from msgspec import UNSET, Struct, UnsetType, to_builtins, defstruct +from msgspec import UNSET, Struct, UnsetType, defstruct, to_builtins PY310 = sys.version_info[:2] >= (3, 10) PY311 = sys.version_info[:2] >= (3, 11) diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 43c2e388..d652363e 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -4,10 +4,11 @@ from typing import Generic, List, Optional, Set, TypeVar import pytest -from .utils import temp_module, package_not_installed from msgspec._utils import get_class_annotations +from .utils import package_not_installed, temp_module + PY310 = sys.version_info[:2] >= (3, 10) T = TypeVar("T") diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 710c77c7..11c2d25d 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -1,5 +1,5 @@ -import sys import inspect +import sys import textwrap import types import uuid