Skip to content

Commit

Permalink
Fix __deprecated_attributes__ usage
Browse files Browse the repository at this point in the history
- The dict needs to live in the module where the deprecated attributes
  are; so here it needs to be hazmat.__deprecated_attributes__.
  (Maybe it would be less confusing to put this in hazmat.py, I don't
  know.)

- Don't export the symbols from trio.hazmat using normal mechanisms;
  that overrides the __deprecated_attributes__ mechanism.

- Then since they're no longer in hazmat, we can't say that
  trio.hazmat.Value resolves to the value trio.hazmat.Value, so point
  the __deprecated_attributes__ entries directly at trio._core._result.*

- In fact, let's stop exporting them from trio._core entirely.

- And then this reveals two tests that were still referring to
  trio._core.Error, so fix those.

Confirmed manually that with these changes I get correct values and
warnings for accessing the public attributes:

In [2]: trio.hazmat.Result
/home/njs/.user-python3.5-64bit/bin/ipython:1: TrioDeprecationWarning: trio.hazmat.Result is deprecated since Trio 0.5.0; use outcome.Outcome instead (#494)
  #!/home/njs/.user-python3.5-64bit/bin/python3.5
Out[2]: trio._core._result.Result  # class

In [3]: trio.hazmat.Value
/home/njs/.user-python3.5-64bit/bin/ipython:1: TrioDeprecationWarning: trio.hazmat.Value is deprecated since Trio 0.5.0; use outcome.Value instead (#494)
  #!/home/njs/.user-python3.5-64bit/bin/python3.5
Out[3]: outcome.Value  # class

In [4]: trio.hazmat.Error
/home/njs/.user-python3.5-64bit/bin/ipython:1: TrioDeprecationWarning: trio.hazmat.Error is deprecated since Trio 0.5.0; use outcome.Error instead (#494)
  #!/home/njs/.user-python3.5-64bit/bin/python3.5
Out[4]: outcome.Error  # class
  • Loading branch information
njsmith committed Apr 21, 2018
1 parent 83fec3f commit ed0510a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
13 changes: 9 additions & 4 deletions trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,25 @@
from . import abc
from . import ssl
# Not imported by default: testing

_deprecate.enable_attribute_deprecations(hazmat.__name__)

__deprecated_attributes__ = {
# Temporary hack to make sure _result is loaded, just during the deprecation
# period
from ._core import _result

hazmat.__deprecated_attributes__ = {
"Result":
_deprecate.DeprecatedAttribute(
hazmat.Result, "0.5.0", issue=494, instead="outcome.Outcome"
_core._result.Result, "0.5.0", issue=494, instead="outcome.Outcome"
),
"Value":
_deprecate.DeprecatedAttribute(
hazmat.Value, "0.5.0", issue=494, instead="outcome.Value"
_core._result.Value, "0.5.0", issue=494, instead="outcome.Value"
),
"Error":
_deprecate.DeprecatedAttribute(
hazmat.Error, "0.5.0", issue=494, instead="outcome.Error"
_core._result.Error, "0.5.0", issue=494, instead="outcome.Error"
)
}

Expand Down
3 changes: 0 additions & 3 deletions trio/_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def _public(fn):
from ._multierror import *
__all__ += _multierror.__all__

from ._result import *
__all__ += _result.__all__

from ._traps import *
__all__ += _traps.__all__

Expand Down
4 changes: 2 additions & 2 deletions trio/_core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ async def child():
async with _core.open_nursery() as nursery:
nursery.start_soon(child)
await wait_all_tasks_blocked()
_core.reschedule(child_task, _core.Error(ValueError()))
_core.reschedule(child_task, outcome.Error(ValueError()))


# Similar to previous test -- if the ValueError() gets sent in via 'throw',
Expand All @@ -1127,7 +1127,7 @@ async def child():
async with _core.open_nursery() as nursery:
nursery.start_soon(child)
await wait_all_tasks_blocked()
_core.reschedule(child_task, _core.Error(ValueError()))
_core.reschedule(child_task, outcome.Error(ValueError()))

assert isinstance(excinfo.value.__context__, KeyError)

Expand Down
3 changes: 0 additions & 3 deletions trio/hazmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# symbols, and then we prune some below if they aren't available on this
# system.
__all__ = [
"Result",
"Value",
"Error",
"cancel_shielded_checkpoint",
"Abort",
"wait_task_rescheduled",
Expand Down

0 comments on commit ed0510a

Please sign in to comment.