Skip to content

Commit

Permalink
Handle re-exporting of platform-specific hazmat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
njsmith committed Sep 6, 2017
1 parent cc7ff17 commit 2091b28
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Fix ``sock.accept()`` for IPv6 sockets (https://github.com/python-trio/trio/issu

deprecate most of the task and nursery APIs

make our exports visible to PyCharm (314)

Renames from https://github.com/python-trio/trio/issues/157

Note that pypy needs 5.9+ to support deprecations properly
Expand Down
1 change: 0 additions & 1 deletion trio/_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async def wait_socket_readable(sock):
raise TypeError("need a socket")
await wait_readable(sock)


async def wait_socket_writable(sock):
if type(sock) != _stdlib_socket.socket:
raise TypeError("need a socket")
Expand Down
50 changes: 41 additions & 9 deletions trio/hazmat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
# These are all re-exported from trio._core. See comments in trio/__init__.py
# for details.
# for details. To make static analysis easier, this lists all possible
# 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", "enable_ki_protection", "disable_ki_protection",
"currently_ki_protected", "Task", "checkpoint", "current_task",
"checkpoint_if_cancelled", "spawn_system_task", "reschedule",
"current_call_soon_thread_and_signal_safe", "wait_writable",
"wait_readable", "ParkingLot", "UnboundedQueue", "RunLocal",
"wait_socket_readable", "wait_socket_writable"
"Result",
"Value",
"Error",
"cancel_shielded_checkpoint",
"Abort",
"wait_task_rescheduled",
"enable_ki_protection",
"disable_ki_protection",
"currently_ki_protected",
"Task",
"checkpoint",
"current_task",
"checkpoint_if_cancelled",
"spawn_system_task",
"reschedule",
"current_call_soon_thread_and_signal_safe",
"wait_writable",
"wait_readable",
"ParkingLot",
"UnboundedQueue",
"RunLocal",
"wait_socket_readable",
"wait_socket_writable",
# kqueue symbols
"current_kqueue",
"monitor_kevent",
"wait_kevent",
# windows symbols
"current_iocp",
"register_with_iocp",
"wait_overlapped",
"monitor_completion_key",
]

from . import _core
globals().update({sym: getattr(_core, sym) for sym in __all__})
# Some hazmat symbols are platform specific
for _sym in list(__all__):
if hasattr(_core, _sym):
globals()[_sym] = getattr(_core, _sym)
else:
__all__.remove(_sym)

0 comments on commit 2091b28

Please sign in to comment.