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

sysconfig imports pprint which imports the world #106789

Closed
iritkatriel opened this issue Jul 15, 2023 · 3 comments · Fixed by #106790
Closed

sysconfig imports pprint which imports the world #106789

iritkatriel opened this issue Jul 15, 2023 · 3 comments · Fixed by #106790
Labels
type-bug An unexpected behavior, bug, or error

Comments

@iritkatriel
Copy link
Member

iritkatriel commented Jul 15, 2023

sysconfig imports pprint in order to print the config dict to a file. But this dict contains only strings and ints, so pprint is overkill.

The problem with importing pprint is that it imports dataclasses, which imports inspect, which imports dis which imports opcode which tries to import _opcode which does not exist in early stages of the build when sysconfig is used. So opcode imports _opcode in a try-except and ignores import errors. Since sysconfig doesn't need anything from _opcode, the partially constructed opcode module suffices. But this is flaky and hard to reason about (it works because it works). It would be better if sysconfig didn't import so much.

Linked PRs

@iritkatriel iritkatriel added the type-bug An unexpected behavior, bug, or error label Jul 15, 2023
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Jul 15, 2023
@gvanrossum
Copy link
Member

Honestly I think that dataclasses shouldn't import inspect, and inspect shouldn't import dis. But if this is the easiest way to fix the issue at hand, let's do it.

@iritkatriel
Copy link
Member Author

I'll look into that. Let's hold off merging this.

@FFY00
Copy link
Member

FFY00 commented Jul 15, 2023

Regardless of other possible solutions, I think removing the sysconfig dependency on pprint is a valuable contribution on its own, so I am happy with it being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants