-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Description
Bug report
Bug description:
Hi everyone,
I noticed that the request method defines headers with a mutable default argument ({}):
# Lib/http/client.py
def request(self, method, url, body=None, headers={}, *, encode_chunked=False):I know the Python docs have a specific warning about this (in Section 4.9.1) because mutable defaults can sometimes accumulate values across calls if they get modified.
It looks like the current code is actually safe because _send_request just reads from the dictionary and doesn't write to it, so I doubt this is causing any bugs right now.
But I was just wondering—is this kept as {} for backward compatibility (maybe for tools inspecting the signature)? Or would it be better to update it to None to follow the standard best practice?
If you think it's worth fixing, I’d be happy to put together a PR for it. If it's better to just leave it alone to be safe, I totally understand!
Thanks!
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response