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
Remove doctest import from heapq #85469
Comments
heapq.py imports doctest in the last 4 lines to perform unit tests: if __name__ == "__main__":
import doctest # pragma: no cover
print(doctest.testmod()) # pragma: no cover This disrupts dependency tracking modules and software, like modulegraph and pyinstaller, as doctest brings in many dependencies (including ctypes as of 3.8). This functionality could be factored out into a separate unit-testing file. |
The idiom of a module running doctests on itself when executed as a script is a common idiom. If modulegraph and pyinstaller can't cope a module importing another module from inside an if statement, that's a bug in them, not in the heapq module (and many others). This requested change is a regression, taking away functionality. 3.8 and older are in feature freeze, so this could only apply to 3.9 and 3.10, and even then, I do not believe it should apply at all. |
I concur with Steven. |
I have no opinion on the proposed change. The "disruption" alex c talks about is that this imports gets seen by modulegraph (and hence pyinstaller and py2app), which will then include doctest and all its dependencies in standalone bundles even though doctest isn't actually used. |
Ronald, can modulegraph be made smarter with respect to sections of code guarded by __name__ == '__main__'? That Python idiom is old and pervasive. |
If not, could modulegraph add a flag to drop imports commonly found in main sections: doctest, unittest, argparse, etc.? Asking the standard library to change seems like the tail wagging the dog — it only paints over the problem since third-party modules, other standard library modules, and user code commonly use main sections as well. |
modulegraph already knows where the import is done, and users of the library can use that information to make decisions. There's no need to make changes to either heapq.py or modulegraph. For py2app I've made the choice to no be smart about inclusions and just try to include everything that may be imported because disk space is cheap these days. I just exclude optional dependencies (in py2app, not modulegraph) when I've manually checked that it is safe to do so and the dependency is large. |
Can we close this? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: