Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
njsmith opened this issue Apr 22, 2019 · 2 comments
Closed

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

njsmith opened this issue Apr 22, 2019 · 2 comments

Comments

@njsmith
Copy link
Member

@njsmith njsmith commented Apr 22, 2019

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.

@amunchet
Copy link

@amunchet amunchet commented Apr 23, 2019

I'm new here, but I'd like to give this a go if no one else already has.

@njsmith
Copy link
Member Author

@njsmith njsmith commented May 1, 2019

Fixed in #1020

@njsmith njsmith closed this May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants