This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: Usage of assert in http/client.py
类型: Stage: patch review
Components: Library (Lib) Versions: Python 3.10
process
状态: open Resolution:
Dependencies: 后续:
分配给: 抄送列表: benjamin.peterson, fbidu, veky
优先级: normal 关键字: patch

fbidu2020-10-17 12:53 创建。最近一次由 admin2022-04-11 14:59 修改。

Pull Requests
URL Status Linked Edit
PR 22737 open fbidu, 2020-10-17 12:55
Messages (3)
msg378810 - (view) Author: Felipe Rodrigues (fbidu) * 日期: 2020-10-17 12:53
Hi all!

I was testing some static analysis tool and decided to use the HTTP module as testing ground. While running `bandit` at the client module, it detected 3 instances of using `assert` inside the code. Twice in the HTTPResponse class and once in the HTTPConnection class.

Now, I know that this will only cause any trouble when running python with the optimize settings turned on and if someone is that concerned about optimization, they probably won't be using the stdlib's HTTP implementation, but I think it would be fitting to fix this corner case.

I've written a PR that fixes this but I'm not sure if the raised exceptions and messages are ok
msg378903 - (view) Author: Vedran Čačić (veky) * 日期: 2020-10-18 21:44
If I understand correctly, those are _private methods_ (names start with underscore). In such cases, asserts can be completely fine, since the library writer controls the situations where the method is called. If it is never called with _UNKNOWN argument, assert is just that, assertion that it is so. (It would be different if it were a public method, since the library writer doesn't know it will never be called with _UNKNOWN.)
msg379078 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) 日期: 2020-10-20 02:34
Are these assertion failures actually reachable due to malformed input? If so, there should be some tests to that effect. Otherwise, if they're actually "impossible" situations, I don't think this change is necessary.
历史
日期 用户 动作 参数
2022-04-11 14:59:36admin修改github: 86226
2020-10-20 02:34:38benjamin.peterson修改抄送: + benjamin.peterson
消息: + msg379078
2020-10-18 21:44:41veky修改抄送: + veky
消息: + msg378903
2020-10-17 12:55:55fbidu修改keywords: + patch
stage: patch review
pull_requests: + pull_request21700
2020-10-17 12:53:09fbidu创建