Skip to content

In trio/*.py, when possible, use public names instead of trio._core.* #1017

@njsmith

Description

@njsmith

In this recent forum post, @math2001 was wondering how to implement something like trio.move_on_after, so they looked at the source... and saw a reference to _core.current_time(), which made them think that it was using spooky private APIs: https://trio.discourse.group/t/how-to-access-the-current-run-s-clock/163

Of course, that's not the goal. Nothing in the trio._core.* API is actually private – it all gets re-exported from trio.*, trio.hazmat.*, or trio.testing.*, and the whole point of having a _core API layer is to make sure that it is possible to implement your own versions of things like move_on_after. But there's no way @math2001 could have known that when they dug into the code :-). And if move_on_after had used trio.current_time() instead of _core.current_time(), then the confusion could have been avoided.

So probably we should do a pass through the files in trio/*.py, and replace references to _core.* with trio.* or trio.hazmat.* as appropriate. There might be some places where this is difficult or annoying (e.g. when implementing trio itself you can't necessarily replace from ._core import <names> with from trio import <names>, because of circular import issues), but for files like trio/_timeouts.py this would be easy to do.

Marking "good first issue" because it's pretty straightforward. For example, in trio/_timeouts.py, it'd be a matter of:

  1. Replacing from . import _core with import trio
  2. Replacing references to _core.current_timetrio.current_time, _core.CancelScopetrio.CancelScope

There are a bunch of files to look through, but for a first issue it'd be fine to just pick one to start with.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions