[issue38297] Imports at top of module is often not used

Dominic Littlewood report at bugs.python.org
Sat Sep 28 05:19:26 EDT 2019


Dominic Littlewood <11dlittlewood at gmail.com> added the comment:

I've slightly adjusted the script to check for module-level imports not at the top of the file. If we permit things like this:

if condition:
    import module
else:
    do_something_sensible()

as long as they are at the top of the file, it seems that only one in ten modules have a problem. Which is better but not great.

A common pattern which breaks the rules is this:

# Large amounts of code here

if __name__ == '__main__':
    import unittest
    unittest.main('test/test_thisfile')

although that by no means accounts for all of the problems.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38297>
_______________________________________


More information about the Python-bugs-list mailing list