Repository navigation
Potential issue: len(Headers) counts duplicate entries, disagreeing with keys()/iteration #3821
Unanswered
Sun-Wukhan
asked this question in
Potential Issue
Replies: 1 comment
|
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Found while property-based testing the models.
Headers presents a Mapping interface, and its keys()/iter deduplicate — but len returns len(self._list), the raw entry count, so len() disagrees with the number of keys the mapping reports. For a plain dict those always agree, and code doing len(headers) to count distinct header names gets a surprising answer when duplicates are present (which is normal for real HTTP traffic, e.g. multiple Set-Cookie... in a Headers instance built from a raw list).
Is the entry-count semantics deliberate (multidict-style) or an oversight? If it should count distinct keys, the fix is one line — len of the keys view — and I can prepare it on a fork branch. Raising it here first since it is a visible behaviour change either way, and PR creation on this repo is limited to collaborators.
All reactions