Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests.package.chardet* references not assigned correctly? #6223

Closed
babyhoo976 opened this issue Aug 31, 2022 · 2 comments
Closed

requests.package.chardet* references not assigned correctly? #6223

babyhoo976 opened this issue Aug 31, 2022 · 2 comments

Comments

@babyhoo976
Copy link

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')])

@amkarn258
Copy link
Contributor

Have proposed a fix here - #6562

@nateprewitt
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants