diff --git a/newsfragments/812.removal.rst b/newsfragments/812.removal.rst new file mode 100644 index 0000000000..8049caad10 --- /dev/null +++ b/newsfragments/812.removal.rst @@ -0,0 +1 @@ +Remove the APIs deprecated in 0.5.0. (``ClosedStreamError``, ``ClosedListenerError``, ``Result``) diff --git a/trio/__init__.py b/trio/__init__.py index e9b6f54448..5e14fa1f09 100644 --- a/trio/__init__.py +++ b/trio/__init__.py @@ -73,20 +73,6 @@ _deprecate.enable_attribute_deprecations(__name__) __deprecated_attributes__ = { - "ClosedStreamError": - _deprecate.DeprecatedAttribute( - ClosedResourceError, - "0.5.0", - issue=36, - instead=ClosedResourceError - ), - "ClosedListenerError": - _deprecate.DeprecatedAttribute( - ClosedResourceError, - "0.5.0", - issue=36, - instead=ClosedResourceError - ), "BrokenStreamError": _deprecate.DeprecatedAttribute( BrokenResourceError, @@ -100,30 +86,6 @@ ), } -_deprecate.enable_attribute_deprecations(hazmat.__name__) - -# Temporary hack to make sure _result is loaded, just during the deprecation -# period -from ._core import _result - -hazmat.__deprecated_attributes__ = { - "Result": - _deprecate.DeprecatedAttribute( - _core._result.Result, - "0.5.0", - issue=494, - instead="outcome.Outcome" - ), - "Value": - _deprecate.DeprecatedAttribute( - _core._result.Value, "0.5.0", issue=494, instead="outcome.Value" - ), - "Error": - _deprecate.DeprecatedAttribute( - _core._result.Error, "0.5.0", issue=494, instead="outcome.Error" - ) -} - # Having the public path in .__module__ attributes is important for: # - exception names in printed tracebacks # - sphinx :show-inheritance: diff --git a/trio/_core/_result.py b/trio/_core/_result.py deleted file mode 100644 index 30b916ff0d..0000000000 --- a/trio/_core/_result.py +++ /dev/null @@ -1,31 +0,0 @@ -import outcome - -from .. import _deprecate - -__all__ = ["Result", "Value", "Error"] - - -class Result(outcome.Outcome): - @classmethod - @_deprecate.deprecated( - version="0.5.0", issue=494, instead="outcome.capture" - ) - def capture(cls, sync_fn, *args): - return outcome.capture(sync_fn, *args) - - @classmethod - @_deprecate.deprecated( - version="0.5.0", issue=494, instead="outcome.acapture" - ) - async def acapture(cls, async_fn, *args): - return await outcome.acapture(async_fn, *args) - - -# alias these types so they don't mysteriously disappear -Value = outcome.Value -Error = outcome.Error - -# ensure that isinstance(Value(), Result)/issubclass(Value, Result) and etc -# don't break -Result.register(Value) -Result.register(Error) diff --git a/trio/_core/tests/test_result.py b/trio/_core/tests/test_result.py deleted file mode 100644 index 5a6bee03d6..0000000000 --- a/trio/_core/tests/test_result.py +++ /dev/null @@ -1,108 +0,0 @@ -import sys -import pytest -from async_generator import async_generator, yield_ - -from ... import _core -from ..._core._result import * - - -def test_Result(recwarn): - v = Value(1) - assert v.value == 1 - assert v.unwrap() == 1 - assert repr(v) == "Value(1)" - - exc = RuntimeError("oops") - e = Error(exc) - assert e.error is exc - with pytest.raises(RuntimeError): - e.unwrap() - assert repr(e) == "Error({!r})".format(exc) - - with pytest.raises(TypeError): - Error("hello") - with pytest.raises(TypeError): - Error(RuntimeError) - - -def test_Result_eq_hash(recwarn): - v1 = Value(["hello"]) - v2 = Value(["hello"]) - v3 = Value("hello") - v4 = Value("hello") - assert v1 == v2 - assert v1 != v3 - with pytest.raises(TypeError): - {v1} - assert {v3, v4} == {v3} - - # exceptions in general compare by identity - exc1 = RuntimeError("oops") - exc2 = KeyError("foo") - e1 = Error(exc1) - e2 = Error(exc1) - e3 = Error(exc2) - e4 = Error(exc2) - assert e1 == e2 - assert e3 == e4 - assert e1 != e3 - assert {e1, e2, e3, e4} == {e1, e3} - - -def test_Value_compare(recwarn): - assert Value(1) < Value(2) - assert not Value(3) < Value(2) - with pytest.raises(TypeError): - Value(1) < Value("foo") - - -def test_Result_capture(recwarn): - def return_arg(x): - return x - - v = Result.capture(return_arg, 2) - assert type(v) == Value - assert v.unwrap() == 2 - - def raise_ValueError(x): - raise ValueError(x) - - e = Result.capture(raise_ValueError, "two") - assert type(e) == Error - assert type(e.error) is ValueError - assert e.error.args == ("two",) - - -async def test_Result_acapture(recwarn): - async def return_arg(x): - await _core.checkpoint() - return x - - v = await Result.acapture(return_arg, 7) - assert v == Value(7) - - async def raise_ValueError(x): - await _core.checkpoint() - raise ValueError(x) - - e = await Result.acapture(raise_ValueError, 9) - assert type(e.error) is ValueError - assert e.error.args == (9,) - - -async def test_Result_asend(recwarn): - @async_generator - async def my_agen_func(): - assert (await yield_(1)) == "value" - with pytest.raises(KeyError): - await yield_(2) - await yield_(3) - - my_agen = my_agen_func().__aiter__() - if sys.version_info < (3, 5, 2): - my_agen = await my_agen - assert (await my_agen.asend(None)) == 1 - assert (await Value("value").asend(my_agen)) == 2 - assert (await Error(KeyError()).asend(my_agen)) == 3 - with pytest.raises(StopAsyncIteration): - await my_agen.asend(None)