Skip to content

gh-111881: Use lazy import in doctest #111888

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

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Nov 9, 2023

Use lazy import for difflib and linecache imports in doctest to speedup Python startup and reduce the number of imports when running tests.

Use lazy import for difflib and linecache imports in doctest to
speedup Python startup and reduce the number of imports when running
tests.
@@ -1528,6 +1528,8 @@ def out(s):
self.debugger.reset()
pdb.set_trace = self.debugger.set_trace

import linecache
Copy link
Member

@AlexWaygood AlexWaygood Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there's much point in making this one a lazy import. How many times does someone import doctest and then not call this method? It's pretty core to the module's functionality, no?

If there are plausible, common situations where someone might import doctest but not call this method, it's worth it to make it a lazy import. But if it just gets imported anyway as soon as doctest is actually used, I think it would be better to continue importing it eagerly at the top of the module, as we're doing now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this change while trying hard to reduce the number of imports in libregrtest. Maybe #111884 makes this change less important.

I converted this PR as a draft for now. I will see how it goes with other changes to decide later if this change is "needed" or not.

@vstinner vstinner marked this pull request as draft November 9, 2023 14:56
@vstinner
Copy link
Member Author

I lost track of this change, so I just close it.

@vstinner vstinner closed this Dec 20, 2023
@vstinner vstinner deleted the import_doctest branch December 20, 2023 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants