Skip to content

Commit

Permalink
remove SuppressableContextManager type now that `AbstractContextMan…
Browse files Browse the repository at this point in the history
…ager` takes a generic
  • Loading branch information
DetachHead committed Jan 6, 2025
1 parent ba646d5 commit 0cc39a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
11 changes: 4 additions & 7 deletions pytest_robotframework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 2 additions & 23 deletions pytest_robotframework/_internal/utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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`)"""

0 comments on commit 0cc39a3

Please sign in to comment.