Skip to content

fix: remove stray debug print calls in production code paths#1

Open
PttCodingMan wants to merge 1 commit intomasterfrom
claude/project-review-feedback-EvSF1
Open

fix: remove stray debug print calls in production code paths#1
PttCodingMan wants to merge 1 commit intomasterfrom
claude/project-review-feedback-EvSF1

Conversation

@PttCodingMan
Copy link
Copy Markdown
Owner

Summary

清掉混進生產程式碼裡的三處 print debug 殘留,全部改走既有的 log.logger 通道,使用者的 stdout 不再被噪訊污染。

  • PTT.py:102print('language', self.config.language) 直接刪除。語言設定原本就會在 init 流程後段透過 log.logger.info(i18n.set_up_lang_module, ...)PTT.py:167-169)正確記錄,這行純粹是 debug 殘留。
  • _api_util.py:221-222parse_query_postexcept 區塊裡的 print(api.cursor) / print(ori_screen) 改成 log.logger.debug(...),受 log level 控管。
  • connect_core.py:188, 289 — 連線與 send_msg 兩處 except 裡的 print(e)(緊跟在 traceback.print_tb(...) 後)改成 log.logger.debug(str(e))

Why

每次 PyPtt.API() 初始化時,stdout 都會跳出一行 language Language.MANDARIN,這對函式庫使用者是純干擾——尤其是把 PyPtt 包進更大的 CLI 或 service 時。其他兩處的 print 同樣繞過了專案自己定義的 log.logger,破壞了 log level 的一致性。

Test plan

  • python -m py_compile 三個改動檔案皆通過
  • python -c "import PyPtt; PyPtt.API(language=PyPtt.Language.MANDARIN)" smoke test:stdout 不再有 language ... 噪訊,logger 仍正確輸出 [INFO] 設定語言模組 ... 繁體中文
  • 連線錯誤路徑(connect_core.py 兩處 except)需要實際斷線情境驗證;目前僅靠 logger 通道的等價性靜態判斷
  • CI flake8 / python tests/init.py

Notes

範圍刻意控制在「真 debug 殘留」三處。以下 print 經檢查是合理用途,未動

  • PTT.py:229-235login() docstring 裡的 範例:: code block
  • PTT.py:1064-1065if __name__ == '__main__': CLI 版本資訊輸出
  • service.py:35,38,41Service docstring 裡的 範例:: code block
  • screens.py:165-191 (show()) — DEBUG-only 螢幕視覺化函式,本身就是 debug 工具
  • screens.py:354check_value.py:60-70__main__ block 裡的手動測試

https://claude.ai/code/session_018UnF3J7NAA125VrQTreYKf


Generated by Claude Code

- PTT.py: drop `print('language', ...)` in API.__init__; the language
  is already reported via `log.logger.info(i18n.set_up_lang_module, ...)`
  later in the init flow.
- _api_util.py: replace debug `print(api.cursor)` / `print(ori_screen)`
  in parse_query_post's except block with `log.logger.debug(...)` so the
  diagnostics are gated by log level.
- connect_core.py: replace `print(e)` after `traceback.print_tb(...)` in
  both the connect and send_msg except blocks with `log.logger.debug(...)`.

No behavior change at default log level beyond removing the unconditional
"language Mandarin" line that leaked to stdout on every API() init.

https://claude.ai/code/session_018UnF3J7NAA125VrQTreYKf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants