Skip to content

Commit c51db6d

Browse files
committed
typing: Make Nullary generic
This ensures that we don't lose type information for the return value. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 6403916 commit c51db6d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

testtools/testcase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import types
2424
import unittest
2525
from collections.abc import Callable, Iterator
26-
from typing import TYPE_CHECKING, NoReturn, ParamSpec, TypeVar, cast, overload
26+
from typing import TYPE_CHECKING, Generic, NoReturn, ParamSpec, TypeVar, cast, overload
2727
from unittest.case import SkipTest
2828

2929
T = TypeVar("T")
@@ -1341,7 +1341,7 @@ def __exit__(
13411341
return True
13421342

13431343

1344-
class Nullary:
1344+
class Nullary(Generic[_R]):
13451345
"""Turn a callable into a nullary callable.
13461346
13471347
The advantage of this over ``lambda: f(*args, **kwargs)`` is that it
@@ -1358,7 +1358,7 @@ def __init__(
13581358
self._args = args
13591359
self._kwargs = kwargs
13601360

1361-
def __call__(self) -> object:
1361+
def __call__(self) -> _R:
13621362
return self._callable_object(*self._args, **self._kwargs)
13631363

13641364
def __repr__(self) -> str:

0 commit comments

Comments
 (0)