avoid using print() function
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
調査の方向性
brping/device.py を開き、2つの print 呼び出しと既存の例外経路を含めて connect_serial() を調査します。デバイスが見つからない場合とオープンに成功する場合を実行し、前者が説明どおりに例外を発生させ、後者が stdout に書き込まなくなっていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5)
def connect_serial(self, device_name: str, baudrate: int =115200):
if device_name is None:
print("Device name is required")
return
try:
print("Opening %s at %d bps" % (device_name, baudrate))
## Serial object for device communication
# write_timeout fixes it getting stuck forever atempting to write to
# /dev/ttyAMA0 on Raspberry Pis, this raises an exception instead.
self.iodev = serial.Serial(device_name, baudrate, write_timeout=1.0)
self.iodev.send_break()
time.sleep(0.001)
self.iodev.write("U".encode("ascii"))
except Exception as exception:
raise Exception("Failed to open the given serial port: {0}".format(exception))
The request here is:
Kindly avoid using the print function in a library like this. If the device name is required, it should be handled as an exception, not with a print and return:
raise ValueError("Device name is required")
And the next print is indeed a logging:
logger.info("Opening %s at %d bps", device_name, baudrate)
I've had to use workarounds to prevent these prints from being sent to my app's stdout:
def brping_muted_print(*args, **kw):
if len(args) == 1:
args = args[0]
log('brping: %s', args)
# brping module uses raw print statements for logging
# with this trick, we turn them into proper logs
brping.device.print = brping_muted_print
Thanks
- 主要言語
- Python
- スター
- 60
- フォーク
- 39
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bluerobotics/ping-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bluerobotics/ping-python#74 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
bluerobotics/ping-python#171 ·
-
set sound speed オープン
bluerobotics/ping-python#169 · コメント 2 件 · 担当者 1 名 ·
-
Code after return オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 48/100
bluerobotics/ping-python#167 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 32/100
bluerobotics/ping-python#159 ·
bluerobotics/ping-python の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
use-agent-os/agent-os#3314 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
BasedHardware/omi#15662 · コメント 1 件 ·
-
documentation help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
AiursoftWeb/AnduinOS-2#19 ·