Skip to content

Commit 5f6971d

Browse files
committed
fix: use ParamSpec in instrument definition instead of tuple and dict
1 parent 44071fc commit 5f6971d

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/pytest_codspeed/instruments/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
from typing import Any, Callable, ClassVar, TypeVar
99

1010
import pytest
11+
from typing_extensions import ParamSpec
1112

1213
from pytest_codspeed.config import BenchmarkMarkerOptions, PedanticOptions
1314
from pytest_codspeed.plugin import CodSpeedConfig
1415

1516
T = TypeVar("T")
17+
P = ParamSpec("P")
1618

1719

1820
class Instrument(metaclass=ABCMeta):
@@ -30,9 +32,9 @@ def measure(
3032
marker_options: BenchmarkMarkerOptions,
3133
name: str,
3234
uri: str,
33-
fn: Callable[..., T],
34-
*args: tuple,
35-
**kwargs: dict[str, Any],
35+
fn: Callable[P, T],
36+
*args: P.args,
37+
**kwargs: P.kwargs,
3638
) -> T: ...
3739

3840
@abstractmethod

src/pytest_codspeed/instruments/valgrind.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pytest import Session
1515

1616
from pytest_codspeed.config import PedanticOptions
17-
from pytest_codspeed.instruments import T
17+
from pytest_codspeed.instruments import P, T
1818
from pytest_codspeed.plugin import BenchmarkMarkerOptions, CodSpeedConfig
1919

2020

@@ -52,9 +52,9 @@ def measure(
5252
marker_options: BenchmarkMarkerOptions,
5353
name: str,
5454
uri: str,
55-
fn: Callable[..., T],
56-
*args: tuple,
57-
**kwargs: dict[str, Any],
55+
fn: Callable[P, T],
56+
*args: P.args,
57+
**kwargs: P.kwargs,
5858
) -> T:
5959
self.benchmark_count += 1
6060

src/pytest_codspeed/instruments/walltime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pytest import Session
2525

2626
from pytest_codspeed.config import PedanticOptions
27-
from pytest_codspeed.instruments import T
27+
from pytest_codspeed.instruments import P, T
2828
from pytest_codspeed.plugin import BenchmarkMarkerOptions, CodSpeedConfig
2929

3030
DEFAULT_WARMUP_TIME_NS = 1_000_000_000
@@ -187,9 +187,9 @@ def measure(
187187
marker_options: BenchmarkMarkerOptions,
188188
name: str,
189189
uri: str,
190-
fn: Callable[..., T],
191-
*args: tuple,
192-
**kwargs: dict[str, Any],
190+
fn: Callable[P, T],
191+
*args: P.args,
192+
**kwargs: P.kwargs,
193193
) -> T:
194194
benchmark_config = BenchmarkConfig.from_codspeed_config_and_marker_data(
195195
self.config, marker_options

src/pytest_codspeed/plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ def wrap_runtest(
265265
plugin: CodSpeedPlugin,
266266
node: pytest.Item,
267267
config: pytest.Config,
268-
fn: Callable[..., T],
269-
) -> Callable[..., T]:
268+
fn: Callable[P, T],
269+
) -> Callable[P, T]:
270270
@functools.wraps(fn)
271-
def wrapped(*args: tuple, **kwargs: dict[str, Any]) -> T:
271+
def wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
272272
return _measure(plugin, node, config, None, fn, args, kwargs)
273273

274274
return wrapped

0 commit comments

Comments
 (0)