糟糕的设计: API 客户端在内部写死
| 212 | print(" ──────────────") |
| 213 | |
| 214 | class BadRuntime: |
| 215 | """糟糕的设计: API 客户端在内部写死""" |
| 216 | def __init__(self): |
| 217 | # 问题: 测试时怎么办? 没网络怎么办? 想换 API 怎么办? |
| 218 | import urllib.request # noqa: F401 — 演示"写死" |
| 219 | self.api_url = "https://api.anthropic.com/v1/messages" |
| 220 | |
| 221 | def run(self, user_input: str): |
| 222 | # 这里直接调 API——无法测试、无法替换 |
| 223 | pass |
| 224 | |
| 225 | print(" class BadRuntime:") |
| 226 | print(" def __init__(self):") |
nothing calls this directly
no outgoing calls
no test coverage detected