Docstring examples in `from_key_val_list` show the pre-3.12 OrderedDict repr
src/requests/utils.py's from_key_val_list docstring shows:
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
Since Python 3.12, collections.OrderedDict.__repr__ uses the regular dict form (cpython gh-101446), so on any currently supported Python this actually prints:
OrderedDict({'key': 'val'})
Reproducer (Python 3.13.5, requests 2.34.2):
>>> from requests.utils import from_key_val_list
>>> from_key_val_list([('key', 'val')])
OrderedDict({'key': 'val'})
>>> from_key_val_list({'key': 'val'})
OrderedDict({'key': 'val'})
The ValueError example in the same docstring is still accurate. Both stale occurrences are on lines 351 and 357, and a grep of the rest of the package found no others.
I have a two-line fix ready on a fork and would be glad to open a pull request if that's welcome. (The compare page says PRs are limited to collaborators, hence this issue.)
Hi! I’d like to work on this issue and submit a PR for the docstring update. Is it okay if I take this up?
Opened a PR that updates those two doctest lines to the 3.12+ OrderedDict repr.
Got a two-line docstring fix up for this — PR incoming.
Correction: I pushed a two-line fix on my fork (TastyHeadphones:fix/from-key-val-list-ordereddict-repr) but this repo does not allow me to open the PR. Happy for a maintainer or collaborator to pull that branch, or for anyone with access to open it.
Branch is ready but this repo blocks CreatePullRequest for non-collaborators:
https://github.com/psf/requests/compare/main...TastyHeadphones:requests:fix/ordereddict-repr-docstring?expand=1
Happy for a maintainer to open it from that, or grant access and I'll file the PR.
I am taking this issue. I will submit a focused documentation-only PR updating both OrderedDict doctest representations for Python 3.12+.
The focused fix is pushed to https://github.com/masyarakatai/requests/tree/fix-7627-ordered-dict-doctest. PR creation is blocked by repository permissions (masyarakatai is not a collaborator); compare and open the PR here: https://github.com/psf/requests/compare/main...masyarakatai:fix-7627-ordered-dict-doctest