From 0cc39a30bf3e64c36f92abeb471ae397d337296d Mon Sep 17 00:00:00 2001 From: detachhead Date: Sun, 5 Jan 2025 19:29:02 +1000 Subject: [PATCH] remove `SuppressableContextManager` type now that `AbstractContextManager` takes a generic --- pytest_robotframework/__init__.py | 11 ++++------- pytest_robotframework/_internal/utils.py | 25 ++---------------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/pytest_robotframework/__init__.py b/pytest_robotframework/__init__.py index aed60a0..66038a8 100644 --- a/pytest_robotframework/__init__.py +++ b/pytest_robotframework/__init__.py @@ -50,7 +50,6 @@ if TYPE_CHECKING: from collections.abc import Iterable, Iterator, Mapping - from pytest_robotframework._internal.utils import SuppressableContextManager RobotVariables: TypeAlias = dict[str, object] """variable names and values to be set on the suite level. see the `set_variables` function""" @@ -203,7 +202,7 @@ def _save_status_reporter_failure(exception: BaseException): def inner( cls, fn: Callable[P, T], - status_reporter: SuppressableContextManager[object], + status_reporter: AbstractContextManager[object, bool], /, *args: P.args, **kwargs: P.kwargs, @@ -256,11 +255,9 @@ def truncate(arg: object) -> str: # afterwards, so that context managers like `pytest.raises` can see the actual # exception instead of `robot.errors.HandlerExecutionFailed` suppress = True - context_manager: SuppressableContextManager[ - object - # nullcontext is typed as returning None which pyright incorrectly marks as - # unreachable. see SuppressableContextManager documentation - ] = ( # pyright:ignore[reportAssignmentType] + # nullcontext is typed as returning None which pyright incorrectly marks as + # unreachable. see https://github.com/DetachHead/basedpyright/issues/10 + context_manager: AbstractContextManager[object, bool] = ( # pyright:ignore[reportAssignmentType] ( _FullStackStatusReporter( data=data, diff --git a/pytest_robotframework/_internal/utils.py b/pytest_robotframework/_internal/utils.py index cbf1ef8..d5b5477 100644 --- a/pytest_robotframework/_internal/utils.py +++ b/pytest_robotframework/_internal/utils.py @@ -1,16 +1,11 @@ from __future__ import annotations -from abc import abstractmethod -from contextlib import AbstractContextManager from functools import wraps -from typing import TYPE_CHECKING, Callable, Protocol, cast +from typing import TYPE_CHECKING, Callable, cast -from basedtyping import P, T, out_T -from typing_extensions import override +from basedtyping import P, T if TYPE_CHECKING: - from types import TracebackType - from typing_extensions import Concatenate @@ -52,21 +47,5 @@ def new_fn(*args: P.args, **kwargs: P.kwargs) -> T: return decorator -class SuppressableContextManager(AbstractContextManager[out_T], Protocol[out_T]): - """removes `None` from the return type of `AbstractContextManager.__exit__` to prevent code - from being incorrectly marked as unreachable by pyright. see https://github.com/microsoft/pyright/issues/6034 - """ - - @abstractmethod - @override - def __exit__( - self, - exc_type: type[BaseException] | None, - exc_value: BaseException | None, - traceback: TracebackType | None, - /, - ) -> bool: ... - - main_package_name = __name__.split(".")[0] """the name of the top level package (should be `pytest_robotframework`)"""