requests icon indicating copy to clipboard operation
requests copied to clipboard

Docstring examples in `from_key_val_list` show the pre-3.12 OrderedDict repr

Open pactender opened this issue 2 months ago • 7 comments

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.)

pactender avatar Sep 17 '26 17:09 pactender

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?

Abirami-26 avatar Sep 25 '26 06:09 Abirami-26

Opened a PR that updates those two doctest lines to the 3.12+ OrderedDict repr.

TastyHeadphones avatar Sep 26 '26 01:09 TastyHeadphones

Got a two-line docstring fix up for this — PR incoming.

TastyHeadphones avatar Sep 26 '26 01:09 TastyHeadphones

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.

TastyHeadphones avatar Sep 26 '26 01:09 TastyHeadphones

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.

TastyHeadphones avatar Sep 26 '26 01:09 TastyHeadphones

I am taking this issue. I will submit a focused documentation-only PR updating both OrderedDict doctest representations for Python 3.12+.

masyarakatai avatar Oct 22 '26 01:10 masyarakatai

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

masyarakatai avatar Oct 22 '26 01:10 masyarakatai