Skip to content

Commit

Permalink
Updated pre-commit modules and fixed new mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Apr 10, 2023
1 parent 9ee9175 commit ff31b3b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ repos:
exclude: "^tests/mypy/negative.py"

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.260
rev: v0.0.261
hooks:
- id: ruff
args: [--fix, --show-fixes]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies: [ "typing_extensions" ]
Expand Down
4 changes: 3 additions & 1 deletion src/typeguard/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def typechecked(
return target

# Find either the first Python wrapper or the actual function
wrapper_class: type[classmethod[Any]] | type[staticmethod[Any]] | None = None
wrapper_class: type[classmethod[Any, Any, Any]] | type[
staticmethod[Any, Any]
] | None = None
if isinstance(target, (classmethod, staticmethod)):
wrapper_class = target.__class__
target = target.__func__
Expand Down
38 changes: 27 additions & 11 deletions src/typeguard/_importhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from importlib.machinery import ModuleSpec, SourceFileLoader
from importlib.util import cache_from_source, decode_source
from inspect import isclass
from os import PathLike
from types import CodeType, ModuleType, TracebackType
from typing import TYPE_CHECKING, Any, Sequence, TypeVar
from unittest.mock import patch
Expand Down Expand Up @@ -66,20 +67,35 @@ def source_to_code(
| mmap
| _CData
| PickleBuffer
| str,
path: str = "<string>",
| str
| ast.Module
| ast.Expression
| ast.Interactive,
path: bytes
| bytearray
| memoryview
| array[Any]
| mmap
| _CData
| PickleBuffer
| str
| PathLike[str] = "<string>",
) -> CodeType:
if isinstance(data, str):
source = data
if isinstance(data, (ast.Module, ast.Expression, ast.Interactive)):
tree = data
else:
source = decode_source(data)
if isinstance(data, str):
source = data
else:
source = decode_source(data)

tree = _call_with_frames_removed(
ast.parse,
source,
path,
"exec",
)

tree = _call_with_frames_removed(
ast.parse,
source,
path,
"exec",
)
tree = TypeguardTransformer().visit(tree)
ast.fix_missing_locations(tree)

Expand Down

0 comments on commit ff31b3b

Please sign in to comment.