← index #7914PR #13000
Off-topic · high · value 1.932
QUERY · ISSUE

docs: add custom coroutinemethod/coroutinefunction directives following CPython

openby dpgeorgeopened 2021-10-19updated 2021-10-19
docs

For documenting async functions/methods, CPython now uses, eg:

   .. coroutinemethod:: read(n=-1)

      Read up to *n* bytes.  If *n* is not provided, or set to ``-1``,
      read until EOF and return all read bytes.

      If EOF was received and the internal buffer is empty,
      return an empty ``bytes`` object.

I think it'd be good to do this in MicroPython's docs.

CANDIDATE · PULL REQUEST

extmod/asyncio: Add `Task` methods from CPython

openby imnotjamesopened 2023-11-17updated 2024-03-07
extmod

This updates the way that Task is defined in the C module for asyncio which implements tasks & task queues. The goal is to bring asyncio in MicroPython slightly closer to CPython.

This adds the following methods to Task:

  • get_coro() - how CPython exposes the coroutine backing the task (CPython Docs)
  • result() - a helper method from CPython for returning the successful response (CPython Docs)
  • exception() - a helper method from CPython for returning the raised values (CPython Docs)
  • cancelled() - helper for true / false if the task has been cancelled (CPython Docs)
  • add_done_callback() - adds a callback to the task for completion or if already complete executes it (CPython docs)
  • remove_done_callback() - removes a specific "done" callback from the task (CPython docs)

~Adds a hash unary operation so Tasks can be added to sets like in CPython.~

~Also adds set_result and set_exception for consistency but neither of these do anything - they raise a RuntimeError because they aren't supported on Tasks. :shrug:~

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied