Repository 指南 · 概覽 · v1
psf / black
“The uncompromising Python code formatter” — 作者自述
- CLI Tools
- Python
- MIT · 開源授權
- 原始 repository
- psf/black
- 來源平台
- GitHub
- 擁有者 / 組織
- psf
- 授權
- MIT · 開源授權
- 分析的版本
- 20622e1259c29bda81831962ace1348ba1921c84
- 最後驗證
原始專案有更新,本指南有部分內容可能已經過時。預設分支已前進到 5fe7881e6e40,2026-10-03 檢查。整份指南描述的是版本 20622e1259c2。版本差異比對發現,本指南引用的 6 個程式碼區域在新版本有變動(列在下面);關於這些區域的敘述在新版本不一定成立,目前還沒有重新核對。
- tests/test_black.py:171-2283 · 行有變動
- tests/test_black.py:2681-3202 · 行有變動
- src/black/__init__.py:554-776 · 行有變動
- src/black/__init__.py:779-874 · 行有變動
- src/black/linegen.py:110-735 · 行有變動
- src/black/linegen.py:750-885 · 行有變動
本頁中文由負責的 AI 編輯依英文正式版本 v1 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文
psf/black Repository 概覽:Python 程式碼格式化工具的結構
本頁用語說明
- Entrypoint record(進入點記錄)
- 分析器標記為「程式可能從這裡開始執行」的檔案。附有 __main__ guard 摘錄時,表示檔案裡有 if __name__ == "__main__": 區塊,摘錄顯示它呼叫了什麼;沒有摘錄時,只是依檔名判斷。
- Bounded static execution path(有界靜態執行路徑)
- 不執行程式、直接從原始碼重建出的呼叫鏈,走到固定步數就停。它說明在紙面上能追到多遠,不代表實際執行時會發生什麼。
- Unresolved boundary(未解析邊界)
- 靜態路徑停下的地方:下一個呼叫進入外部函式庫,或不執行就無法確定。這是本次分析的邊界,不是 repository 的缺陷。
- Static relations(靜態關係)
- 在原始碼中找到的呼叫與 import。「external or unresolved」表示指向分析範圍以外。
- Module role(模組角色)
- 分析器依呼叫進出次數推論的檔案標籤(例如 core、entry/orchestration、leaf)。它描述的是在呼叫圖中的位置,不是作者的設計意圖。
- Test-like files(類測試檔案)
- 名稱或位置看起來像測試的檔案。本次分析只計數,不執行。
- Observed · inferred · author-claimed · unresolved
- 每句話的依據:直接讀自分析的檔案;由分析器從檔案推論;repository 作者自述(metadata、README);或本次分析無法確定。
- Verified(已驗證)
- 本頁有兩種用法。在分析器的記錄裡(「verified provenance」「verified entrypoint」),它表示這筆記錄是直接從分析的檔案讀到的,也就是本指南所說的 observed;以進入點來說,就是檔案裡確實有 __main__ guard 的文字。分析器在 2026-10-04 修正後,只有 cli.py、main.py 這類像進入點的檔名、沒有 guard 的檔案,會記為 inferred(推測);在那之前分析的指南仍把這類檔案標成 verified,它依然只是對檔案用途的推測。它不代表程式被執行或測試過。「最後驗證」是這份指南最後一次通過本實驗室檢查的日期,檢查對象是所標示版本的分析記錄,不是對 repository 本身的審查。
依 GitHub 的描述,這是一個 Python 程式碼格式化工具,分成 src、tests、docs 和 scripts 幾個子系統。靜態分析涵蓋 482 個檔案和 9,339 條關係,其中有 326 個類測試檔案;但有 8,487 條關係仍未解析,沒有執行任何執行路徑,也沒有解析出的依賴記錄。
這個 repository 是什麼
GitHub metadata 把這個 repository 描述為「The uncompromising Python code formatter」(毫不妥協的 Python 程式碼格式化工具),並列出文件首頁 https://black.readthedocs.io/en/stable/ 。它的 topic 標籤包括 python、formatter、codeformatter 和 pre-commit-hook。平台 metadata 回報的主要語言是 Python,在記錄到的語言分布中有 5,440,093 個 Python 位元組。分析處理了 482 個檔案,並指出 action/main.py 是偵測到的起點。記錄到的授權是 MIT。計數器記錄到 41,844 個 star(截至 2026-09-14),最新 release 是 2026-05-18 發布的 26.5.1。描述和首頁是來自 GitHub API 的作者自述值;topic、語言、授權、star 和 release 欄位則是觀察到的平台記錄。
執行怎麼開始
分析器依檔名啟發式規則,把 action/main.py 標為可能的可執行進入點。從它追出的有界執行路徑到達 os.getenv 和 Path,然後就停在未解析的外部邊界,所以從這個檔案能靜態看到的流程很淺。主要的套件各自帶有 __main__ 守衛:
src/black/__init__.py以if __name__ == "__main__": patched_main()結尾src/blackd/__init__.py用的是同樣的patched_main()模式src/blib2to3/pgen2/driver.py在守衛底下透過sys.exit(int(not main()))結束scripts/generate_schema.py呼叫main();scripts/release.py呼叫sys.exit(main())
分析總共記錄了 18 個進入點和 176 條有界執行路徑。
目錄配置與樞紐模組
有四個頂層目錄被標為可能的子系統:docs、scripts、src 和 tests。記錄到的關係圖有 9,339 條邊:8,219 個呼叫和 1,120 個 import,其中 8,487 條是外部或未解析,852 條在本地解析。角色候選是依已靜態解析的呼叫次數計算的:
src/black/linegen.py(79 個呼入/79 個呼出)和src/black/trans.py(66/66)是 service/core 候選,符合樞紐式格式化邏輯的樣貌。- 在列出的角色中,
tests/util.py的呼入次數最高(118 入/18 出);tests/test_black.py的呼出次數最高(104 入/177 出)。 src/black/__init__.py是 entry/orchestration 候選(42/42);comments.py、nodes.py和files.py是中等連結度的 service/core 候選。
因為大部分關係都未解析,這些次數只描述已在本地解析的那一部分。
依賴證據與測試面
這個 repository 有 7 個建置/依賴清單檔。這次分析的依賴解析只讀 requirements 形式的清單檔,略過 pyproject.toml 的依賴表,所以這份分析資料沒有逐項列出任何具體的依賴記錄。tests 目錄提供了 326 個類測試檔案。
測試面:
tests/test_black.py定義了 BlackTestCase(第 171-2283 行),以及 TestCaching、TestFileCollection、TestDeFactoAPI 和 TestASTSafety 類別。tests/util.py定義了共用的輔助函式:assert_format、all_data_cases 和 read_data。scripts/fuzz.py在它的__main__守衛底下執行 test_idempotent_any_syntactically_valid_python,註解裡說明在有 Atheris 時可選擇進行 coverage-guided fuzzing。
簡短的閱讀順序
README.md和pyproject.toml:分析器把兩者都歸為專案層級的重要檔案。因為擷取是逐行進行的,來自 README 的陳述請當作作者自述。LICENSE:記錄到的授權是 MIT。src/black/__init__.py:先讀 main()(第 554-776 行),再讀 get_sources()(779-874)和 reformat_code()(877-904)。src/black/linegen.py:LineGenerator(110-735)和 transform_line(750-885)都在這裡;依呼叫次數,它是核心候選。src/black/trans.py也是。action/main.py:分析器標記的起始進入點,所以是合理的第一站。
這次分析無法確立的事
- 記錄到的 9,339 條靜態關係中有 8,487 條是外部或未解析。
- 反射、執行期依賴注入、動態 import、monkey-patching、產生的程式碼、框架在執行期的接線和動態分派都沒有解析,所以透過這些機制進行的外掛式載入,這次分析沒有追蹤。
- 安裝、執行與建置的推論並不完整,安裝指令也沒有確認。
- 依賴解析只涵蓋 requirements 形式的清單檔,所以這裡沒有逐項列出宣告的依賴。
- 分析資料裡從 action/main.py 出發的每一條有界執行路徑,都以 unresolved_boundary 為由結束;沒有一條被實際執行。
- manifest 的能力欄位描述的是分析器本身,不是被分析的 repository,因此不算在 repository 的證據裡。
- 分析資料的目錄清單裡有一個頂層的
plugin目錄,但資料中沒有任何內容能確定它怎麼被發現或載入;這一點仍未解決。
這次分析無法確定的事
這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。
- 9,339 條靜態關係中有 8,487 條是外部或未解析,所以呼叫次數的數字只描述在本地解析的 852 條邊。
- 沒有解析出任何具體的依賴記錄(只讀 requirements 形式的清單檔;略過 pyproject.toml 的依賴表),所以從這份分析資料看不出宣告的依賴。
- 沒有執行任何進入點或執行路徑;安裝、執行與建置的行為只有部分推論,也沒有確認。
- 「service/core candidate」這類角色標籤是分析器從已解析的呼叫次數推論的,不是確認過的職責。
- 重要檔案清單排除了 'readme.md',因為它是大小寫不同、不在被分析清單裡的路徑,所以從 README 得到的理解可能不完整。
- 頂層的 'plugin' 和 'autoload' 目錄出現在目錄清單裡,但分析資料沒有任何關於它們怎麼被載入的證據。
陳述與依據 — 38 條陳述,38 條經獨立驗證者確認(英文原文)
上面每一句都是一條陳述,各自引用分析裡的依據編號。編號是這次分析內部的;表格列出每條陳述靠的是什麼、依據有多強。
Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.
| Claim | Epistemic status | Verifier | Grounding (global IDs) |
|---|---|---|---|
| c1 GitHub repository metadata states the description "The uncompromising Python code formatter"; this is an author-claimed value from the GitHub API. | author_claimed | supported | analysis_f07f1c5b3429400e:meta_description |
| c2 The GitHub metadata lists the homepage https://black.readthedocs.io/en/stable/; author-claimed, not confirmed by the analysis. | author_claimed | supported | analysis_f07f1c5b3429400e:meta_homepage |
| c3 The repository's observed topic tags include python, formatter, codeformatter, and pre-commit-hook. | observed | supported | analysis_f07f1c5b3429400e:meta_topics |
| c4 Platform metadata reports Python as the primary language, with 5,440,093 Python bytes in the recorded language breakdown. | observed | supported | analysis_f07f1c5b3429400e:meta_primary_language, analysis_f07f1c5b3429400e:meta_language_bytes |
| c5 The analysis reports 482 analyzed files and names action/main.py as a detected starting point. | observed | supported | analysis_f07f1c5b3429400e:claim_227144a415af |
| c6 The recorded license for the repository is MIT. | observed | supported | analysis_f07f1c5b3429400e:meta_license |
| c7 Platform counters recorded 41,844 stars at 2026-09-14 and a latest release 26.5.1 published 2026-05-18. | observed | supported | analysis_f07f1c5b3429400e:meta_stars, analysis_f07f1c5b3429400e:meta_latest_release |
| c8 The analyzer flags action/main.py as a likely executable entrypoint based on a filename heuristic. | observed | supported | analysis_f07f1c5b3429400e:entry_1 |
| c9 Bounded execution paths traced from action/main.py reach os.getenv and Path and terminate at unresolved external boundaries, so this statically traced flow is shallow. | inferred | supported | analysis_f07f1c5b3429400e:exec_5daffbde25d6, analysis_f07f1c5b3429400e:exec_bfd58df29904 |
| c10 src/black/__init__.py contains a __main__ execution guard whose body calls patched_main(). | observed | supported | analysis_f07f1c5b3429400e:py_entry_fce0ce2b9b79 |
| c11 src/blackd/__init__.py contains a __main__ execution guard whose body calls patched_main(). | observed | supported | analysis_f07f1c5b3429400e:py_entry_479e85cc920d |
| c12 src/blib2to3/pgen2/driver.py contains a __main__ guard that exits through sys.exit(int(not main())). | observed | supported | analysis_f07f1c5b3429400e:py_entry_fae1962d2b1e |
| c13 scripts/generate_schema.py and scripts/release.py contain __main__ guards calling main() and sys.exit(main()) respectively. | observed | supported | analysis_f07f1c5b3429400e:py_entry_2d43f7cb959d, analysis_f07f1c5b3429400e:py_entry_8be0649f8947 |
| c14 The architecture reconstruction reports 18 entrypoints and 176 bounded execution paths; treat as inference. | inferred | supported | analysis_f07f1c5b3429400e:claim_31723c5d9328 |
| c15 The top-level directories docs, scripts, src, and tests are each flagged as likely subsystems. | observed | supported | analysis_f07f1c5b3429400e:subsys_1, analysis_f07f1c5b3429400e:subsys_2, analysis_f07f1c5b3429400e:subsys_3, analysis_f07f1c5b3429400e:subsys_4 |
| c16 The relation graph records 9,339 static relations (8,219 calls, 1,120 imports); 8,487 are external or unresolved and 852 resolve locally. | observed | supported | analysis_f07f1c5b3429400e:relation_counts |
| c17 src/black/linegen.py (79 incoming / 79 outgoing) and src/black/trans.py (66 / 66) are service/core candidates by statically resolved call degree, consistent with hub-like formatting logic. | inferred | supported | analysis_f07f1c5b3429400e:role_19, analysis_f07f1c5b3429400e:role_27 |
| c18 tests/util.py has the highest incoming degree among listed roles (118 in / 18 out), and tests/test_black.py the highest outgoing degree (104 in / 177 out). | inferred | supported | analysis_f07f1c5b3429400e:role_56, analysis_f07f1c5b3429400e:role_48 |
| c19 src/black/__init__.py is an entry/orchestration candidate (42 / 42); src/black/comments.py, src/black/nodes.py, and src/black/files.py are moderate-degree service/core candidates. | inferred | supported | analysis_f07f1c5b3429400e:role_11, analysis_f07f1c5b3429400e:role_14, analysis_f07f1c5b3429400e:role_21, analysis_f07f1c5b3429400e:role_17 |
| c20 The repository contains 7 build/dependency manifest files. | observed | supported | analysis_f07f1c5b3429400e:ev_manifest_1 |
| c21 Dependency parsing in this analysis reads only requirements-style manifests and does not parse pyproject.toml dependency tables, so the packet itemizes no concrete dependency records. | observed | supported | analysis_f07f1c5b3429400e:lim_3 |
| c22 The repository contains 326 test file(s) or test-like file(s). | observed | supported | analysis_f07f1c5b3429400e:ev_tests_1 |
| c23 tests/test_black.py defines BlackTestCase (lines 171-2283) plus the TestCaching, TestFileCollection, TestDeFactoAPI, and TestASTSafety classes. | observed | supported | analysis_f07f1c5b3429400e:py_class_cc5c0d3263dd, analysis_f07f1c5b3429400e:py_class_963874ffa66c, analysis_f07f1c5b3429400e:py_class_eecb79e09b7b, analysis_f07f1c5b3429400e:py_class_d305ef435760, analysis_f07f1c5b3429400e:py_class_cf2968890552 |
| c24 tests/util.py defines the shared helpers assert_format, all_data_cases, and read_data. | observed | supported | analysis_f07f1c5b3429400e:py_func_51a64879d62b, analysis_f07f1c5b3429400e:py_func_aa7b829266dd, analysis_f07f1c5b3429400e:py_func_43cfd58bc242 |
| c25 scripts/fuzz.py's __main__ guard runs test_idempotent_any_syntactically_valid_python, and its comments describe optional coverage-guided fuzzing when Atheris is available. | observed | supported | analysis_f07f1c5b3429400e:py_entry_45e63aec2981 |
| c26 The analyzer classifies README.md and pyproject.toml as project-level important files. | observed | supported | analysis_f07f1c5b3429400e:important_1, analysis_f07f1c5b3429400e:important_3 |
| c27 LICENSE is a project-level important file and the recorded license is MIT. | observed | supported | analysis_f07f1c5b3429400e:important_4, analysis_f07f1c5b3429400e:meta_license |
| c28 In src/black/__init__.py, read main() (lines 554-776), then get_sources() (779-874) and reformat_code() (877-904). | observed | supported | analysis_f07f1c5b3429400e:py_func_e9acdca9deb3, analysis_f07f1c5b3429400e:py_func_e9c2cf3b049c, analysis_f07f1c5b3429400e:py_func_05e93ec52b24 |
| c29 src/black/linegen.py contains LineGenerator (lines 110-735) and transform_line (750-885); linegen.py and trans.py are core candidates by call degree. | inferred | supported | analysis_f07f1c5b3429400e:py_class_b0018f23e219, analysis_f07f1c5b3429400e:py_func_fbd01883b450, analysis_f07f1c5b3429400e:role_19, analysis_f07f1c5b3429400e:role_27 |
| c30 Treat README-derived statements as author claims: extraction in this analyzer is line-based and may capture code lines instead of prose. | observed | supported | analysis_f07f1c5b3429400e:lim_4 |
| c31 action/main.py is the analyzer's flagged starting entrypoint, so it is a reasonable first stop. | observed | supported | analysis_f07f1c5b3429400e:entry_1 |
| c32 8,487 of the 9,339 recorded static relations are external or unresolved. | observed | supported | analysis_f07f1c5b3429400e:relation_counts |
| c33 Because reflection, dynamic imports, monkey-patching, generated code, framework runtime wiring, dynamic dispatch, and dependency injection are not resolved, plugin-style loading through such mechanisms is not traced by this analysis. | inferred | supported | analysis_f07f1c5b3429400e:lim_1 |
| c34 Install, run, and build inference is partial, and installation commands are unconfirmed. | observed | supported | analysis_f07f1c5b3429400e:lim_2 |
| c35 Dependency parsing covered only requirements-style manifests, so the declared dependency set is not itemized in this packet. | observed | supported | analysis_f07f1c5b3429400e:lim_3 |
| c36 The bounded execution paths that start at action/main.py all terminate with reason unresolved_boundary; none was executed. | inferred | supported | analysis_f07f1c5b3429400e:exec_bfd58df29904, analysis_f07f1c5b3429400e:exec_5daffbde25d6, analysis_f07f1c5b3429400e:exec_c1026a562fe1 |
| c37 The manifest's project.actual_capabilities / non_capabilities fields describe the analyzer, not the analyzed repository, and are excluded from repository evidence. | observed | supported | analysis_f07f1c5b3429400e:lim_5 |
| c38 The packet's directory listing includes a top-level 'plugin' directory, but nothing in the packet establishes how it is discovered or loaded; this is not established. | unresolved | supported | analysis_f07f1c5b3429400e:summary_repository |
來源、權利與說明 · attribution-license-templates/v0.1
權利聲明。原始 repository 託管於 GitHub。其原始碼、文件、名稱、媒體與相關素材的權利,仍屬各自的作者、貢獻者與其他權利人所有,並受該 repository 的授權條款約束。
Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.
平台聲明。GitHub 是所連結 repository 的來源託管平台。GitHub 與相關標誌為 GitHub, Inc. 的商標。除非另有明確說明,EVEMISS Technology 與 GitHub 之間沒有隸屬或背書關係。
GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.
這一頁怎麼來的。本頁由對應版本的 repository 分析與 AI 輔助的編輯工具產生。技術陳述綁定所分析的版本;原始 repository 更新後,可能重新驗證。
This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.
本頁包含 AI 輔助分析,並經 EVEMISS Technology 人工與 AI 協力審閱。 · 回報權利疑慮 · 所有 repository 指南