From 1950db184e966b06129f545c558daf969ef9580e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Thu, 27 Jul 2023 16:01:42 +0300 Subject: [PATCH] Updated pre-commit modules --- .pre-commit-config.yaml | 6 +++--- src/typeguard/_importhook.py | 40 ++++++++---------------------------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c16edc3..ed3ee7e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,19 +14,19 @@ repos: - id: trailing-whitespace - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.272 + rev: v0.0.280 hooks: - id: ruff args: [--fix, --show-fixes] - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black exclude: "^tests/mypy/negative.py" - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.3.0 + rev: v1.4.1 hooks: - id: mypy additional_dependencies: [ "typing_extensions" ] diff --git a/src/typeguard/_importhook.py b/src/typeguard/_importhook.py index 84548c1..8590540 100644 --- a/src/typeguard/_importhook.py +++ b/src/typeguard/_importhook.py @@ -10,12 +10,17 @@ from inspect import isclass from os import PathLike from types import CodeType, ModuleType, TracebackType -from typing import TYPE_CHECKING, Any, Sequence, TypeVar +from typing import Sequence, TypeVar from unittest.mock import patch from ._config import global_config from ._transformer import TypeguardTransformer +if sys.version_info >= (3, 12): + from collections.abc import Buffer +else: + from typing_extensions import Buffer + if sys.version_info >= (3, 11): from typing import ParamSpec else: @@ -26,17 +31,6 @@ else: from importlib_metadata import PackageNotFoundError, version -if TYPE_CHECKING: - from array import array - from mmap import mmap - from pickle import PickleBuffer - - # This is guarded because sphinx-autodoc-typehints tries to import these - try: - from ctypes import _CData - except ImportError: - pass - try: OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3]) except PackageNotFoundError: @@ -60,26 +54,8 @@ def optimized_cache_from_source(path: str, debug_override: bool | None = None) - class TypeguardLoader(SourceFileLoader): @staticmethod def source_to_code( - data: bytes - | bytearray - | memoryview - | array[Any] - | mmap - | _CData - | PickleBuffer - | str - | ast.Module - | ast.Expression - | ast.Interactive, - path: bytes - | bytearray - | memoryview - | array[Any] - | mmap - | _CData - | PickleBuffer - | str - | PathLike[str] = "", + data: Buffer | str | ast.Module | ast.Expression | ast.Interactive, + path: Buffer | str | PathLike[str] = "", ) -> CodeType: if isinstance(data, (ast.Module, ast.Expression, ast.Interactive)): tree = data