diff --git a/trio/hazmat.py b/trio/hazmat.py index d39e51d715..eaab2ea3dd 100644 --- a/trio/hazmat.py +++ b/trio/hazmat.py @@ -10,64 +10,50 @@ # this lists all possible symbols from trio._core, and then we prune those that # aren't available on this system. After that we add some symbols from trio/*.py. -__all__ = [ - "cancel_shielded_checkpoint", - "Abort", - "wait_task_rescheduled", - "enable_ki_protection", - "disable_ki_protection", - "currently_ki_protected", - "Task", - "checkpoint", - "current_task", - "current_root_task", - "checkpoint_if_cancelled", - "spawn_system_task", - "reschedule", - "remove_instrument", - "add_instrument", - "current_clock", - "current_statistics", - "ParkingLot", - "UnboundedQueue", - "RunVar", - "wait_writable", - "wait_readable", - "notify_fd_close", - "wait_socket_readable", - "wait_socket_writable", - "notify_socket_close", - "TrioToken", - "current_trio_token", - "temporarily_detach_coroutine_object", - "permanently_detach_coroutine_object", - "reattach_detached_coroutine_object", - # kqueue symbols - "current_kqueue", - "monitor_kevent", - "wait_kevent", - # windows symbols - "current_iocp", - "register_with_iocp", - "wait_overlapped", - "monitor_completion_key", -] +# Generally available symbols +from ._core import ( + cancel_shielded_checkpoint, Abort, wait_task_rescheduled, + enable_ki_protection, disable_ki_protection, currently_ki_protected, Task, + checkpoint, current_task, ParkingLot, UnboundedQueue, RunVar, TrioToken, + current_trio_token, temporarily_detach_coroutine_object, + permanently_detach_coroutine_object, reattach_detached_coroutine_object, + current_statistics, reschedule, remove_instrument, add_instrument, + current_clock, current_root_task, checkpoint_if_cancelled, + spawn_system_task, wait_socket_readable, wait_socket_writable, + notify_socket_close +) + +# Unix-specific symbols +try: + from ._core import ( + wait_writable, + wait_readable, + notify_fd_close, + ) +except ImportError: + pass + +# Kqueue-specific symbols +try: + from ._core import ( + current_kqueue, + monitor_kevent, + wait_kevent, + ) +except ImportError: + pass + +# Windows symbols +try: + from ._core import ( + current_iocp, register_with_iocp, wait_overlapped, + monitor_completion_key + ) +except ImportError: + pass from . import _core -# Some hazmat symbols are platform specific -for _sym in list(__all__): - if hasattr(_core, _sym): - globals()[_sym] = getattr(_core, _sym) - else: - # Fool static analysis (at least PyCharm's) into thinking that we're - # not modifying __all__, so it can trust the static list up above. - # https://github.com/python-trio/trio/pull/316#issuecomment-328255867 - # This was useful in September 2017. If it's not September 2017 then - # who knows. - remove_from_all = __all__.remove - remove_from_all(_sym) # Import bits from trio/*.py if sys.platform.startswith("win"): from ._wait_for_object import WaitForSingleObject - __all__ += ["WaitForSingleObject"] diff --git a/trio/tests/test_exports.py b/trio/tests/test_exports.py index 1c841cd8e0..265ba191d0 100644 --- a/trio/tests/test_exports.py +++ b/trio/tests/test_exports.py @@ -49,9 +49,6 @@ def public_namespaces(module): NAMESPACES = list(public_namespaces(trio)) -# Not yet set up for static analysis: -NAMESPACES.remove("trio.hazmat") - # pylint/jedi often have trouble with alpha releases, where Python's internals # are in flux, grammar may not have settled down, etc.