|
3 | 3 | import warnings
|
4 | 4 | from typing import Any
|
5 | 5 | from typing import Callable
|
| 6 | +from typing import cast |
6 | 7 | from typing import Collection
|
7 | 8 | from typing import Iterable
|
8 | 9 | from typing import Iterator
|
@@ -264,9 +265,9 @@ def combined_with(self, other: "Mark") -> "Mark":
|
264 | 265 |
|
265 | 266 |
|
266 | 267 | # A generic parameter designating an object to which a Mark may
|
267 |
| -# be applied -- a test function (callable) or class. |
| 268 | +# be applied -- a test function (callable) or class (also callable). |
268 | 269 | # Note: a lambda is not allowed, but this can't be represented.
|
269 |
| -Markable = TypeVar("Markable", bound=Union[Callable[..., object], type]) |
| 270 | +Markable = TypeVar("Markable", bound=Callable[..., Any]) |
270 | 271 |
|
271 | 272 |
|
272 | 273 | @attr.s(init=False, auto_attribs=True)
|
@@ -344,25 +345,22 @@ def with_args(self, *args: object, **kwargs: object) -> "MarkDecorator":
|
344 | 345 | mark = Mark(self.name, args, kwargs, _ispytest=True)
|
345 | 346 | return MarkDecorator(self.mark.combined_with(mark), _ispytest=True)
|
346 | 347 |
|
347 |
| - # Type ignored because the overloads overlap with an incompatible |
348 |
| - # return type. Not much we can do about that. Thankfully mypy picks |
349 |
| - # the first match so it works out even if we break the rules. |
350 | 348 | @overload
|
351 |
| - def __call__(self, arg: Markable) -> Markable: # type: ignore[misc] |
| 349 | + def __call__(self, arg: Markable) -> Markable: |
352 | 350 | pass
|
353 | 351 |
|
354 | 352 | @overload
|
355 |
| - def __call__(self, *args: object, **kwargs: object) -> "MarkDecorator": |
| 353 | + def __call__(self, *args: Any, **kwargs: Any) -> "MarkDecorator": |
356 | 354 | pass
|
357 | 355 |
|
358 |
| - def __call__(self, *args: object, **kwargs: object): |
| 356 | + def __call__(self, *args: Any, **kwargs: Any) -> Union[Markable, "MarkDecorator"]: |
359 | 357 | """Call the MarkDecorator."""
|
360 | 358 | if args and not kwargs:
|
361 | 359 | func = args[0]
|
362 | 360 | is_class = inspect.isclass(func)
|
363 | 361 | if len(args) == 1 and (istestfunc(func) or is_class):
|
364 | 362 | store_mark(func, self.mark)
|
365 |
| - return func |
| 363 | + return cast(Markable, func) |
366 | 364 | return self.with_args(*args, **kwargs)
|
367 | 365 |
|
368 | 366 |
|
|
0 commit comments