forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
audiobusio.PDMIn.record() documentation incorrect #10782
Copy link
Copy link
Closed
Labels
Milestone
Description
Happened to be looking at the docs, and noticed that the docstring and type annotation do not match. Looking at shared-bindings, it looks like it could be EITHER int or None depending on the input buffer (and whether it is actually a writable buffer):
import board
import audiobusio
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA)
buffer = bytearray(100)
print(mic.record(buffer, 10)) # prints 10
print(mic.record(123, 10)) # prints NoneIs this intended behavior, or should it return a TypeError here? If this is intended behavior to silent ignore this and return None, I'll update the docstring - otherwise I can update to return an error.
On the topic of the documentation, the docstring also mentions IOError which I believe should be updated to OSError now.
For reference:
circuitpython/shared-bindings/audiobusio/PDMIn.c
Lines 158 to 168 in 57aec3a
| //| def record(self, destination: WriteableBuffer, destination_length: int) -> None: | |
| //| """Records destination_length bytes of samples to destination. This is | |
| //| blocking. | |
| //| | |
| //| An IOError may be raised when the destination is too slow to record the | |
| //| audio at the given rate. For internal flash, writing all 1s to the file | |
| //| before recording is recommended to speed up writes. | |
| //| | |
| //| :return: The number of samples recorded. If this is less than ``destination_length``, | |
| //| some samples were missed due to processing time.""" | |
| //| ... |
Reactions are currently unavailable