Skip to content

Commit ff66108

Browse files
committed
Fix mypy untyped decorators error
This was straight forward using legacy ParamSpec syntax: https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
1 parent 2932e12 commit ff66108

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ warn_unused_configs = True
44
warn_redundant_casts = True
55
warn_unused_ignores = True
66
no_implicit_reexport = True
7+
disallow_subclassing_any = True
8+
disallow_untyped_decorators = True
79

810
[mypy-test.*]
911
disallow_untyped_defs = True

pygit2/callbacks.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from collections.abc import Callable, Generator
6767
from contextlib import contextmanager
6868
from functools import wraps
69-
from typing import TYPE_CHECKING, Optional
69+
from typing import TYPE_CHECKING, Optional, ParamSpec, TypeVar
7070

7171
# pygit2
7272
from ._pygit2 import DiffFile, Oid
@@ -490,8 +490,11 @@ def git_remote_callbacks(payload):
490490
# exception.
491491
#
492492

493+
P = ParamSpec('P')
494+
T = TypeVar('T')
493495

494-
def libgit2_callback(f):
496+
497+
def libgit2_callback(f: Callable[P, T]) -> Callable[P, T]:
495498
@wraps(f)
496499
def wrapper(*args):
497500
data = ffi.from_handle(args[-1])
@@ -509,10 +512,10 @@ def wrapper(*args):
509512
data._stored_exception = e
510513
return C.GIT_EUSER
511514

512-
return ffi.def_extern()(wrapper)
515+
return ffi.def_extern()(wrapper) # type: ignore[attr-defined]
513516

514517

515-
def libgit2_callback_void(f):
518+
def libgit2_callback_void(f: Callable[P, T]) -> Callable[P, T]:
516519
@wraps(f)
517520
def wrapper(*args):
518521
data = ffi.from_handle(args[-1])
@@ -529,7 +532,7 @@ def wrapper(*args):
529532
data._stored_exception = e
530533
pass # Function returns void, so we can't do much here.
531534

532-
return ffi.def_extern()(wrapper)
535+
return ffi.def_extern()(wrapper) # type: ignore[attr-defined]
533536

534537

535538
@libgit2_callback

0 commit comments

Comments
 (0)