requests icon indicating copy to clipboard operation
requests copied to clipboard

requests.package.chardet* references not assigned correctly?

Open babyhoo976 opened this issue 3 years ago • 1 comments
trafficstars

I found that packages.py is assigning sys.modules['requests.package.chardet'] over and over with different modules, is this intentional or a bug?

I looked at the code and this target variable confuses me, it is assigned again in loop and placed with itself(so completely?), looks like a name confliction to me. Code is referenced from installed version 2.28.1.

target = chardet.__name__
for mod in list(sys.modules):
    if mod == target or mod.startswith(f"{target}."):
        target = target.replace(target, "chardet")
        sys.modules[f"requests.packages.{target}"] = sys.modules[mod]

Expected Result

every chardet.* package maps to requests.packages.chardet.* respectively

Actual Result

only requests.package.chardet is assigned at last.

Reproduction Steps

import requests import sys print([m for m in sys.modules if name.startswith('requests.packages.chardet')])

babyhoo976 avatar Aug 31 '22 10:08 babyhoo976

Have proposed a fix here - https://github.com/psf/requests/pull/6562

amkarn258 avatar Oct 30 '23 19:10 amkarn258

Resolving as it appears #6562 ended up merged without closing this. Thanks @amkarn258!

nateprewitt avatar May 14 '24 22:05 nateprewitt