4 ms·
One thing the PEP doesn't really talk about, and that I find very annoying is that many python linters will complain if you don't put all of your imports at the
by thayne 1y ago
One thing the PEP doesn't really talk about, and that I find very annoying is that many python linters will complain if you don't put all of your imports at the top of the file, so you get lint warnings if you do the most obvious way to implement lazy imports.
And that is actually a problem for more than just performance. In some cases, importing at the top might actually just fail. For example if you need a platform specific library, but only if it is running on that platform.
- bcoates 1y agoI don't think there is any solution for that but "fix your broken linter".
- thayne 1y agoIt isn't just one though. Every linter I've used has warned about that. Probably because PEP 8 says > Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants
- BHSPitMonkey 1y agoRuff doesn't do this, and in fact even lets you specify modules that _must_ not be imported at the top level (banned-module-level-imports = [...]) I banished the worst/heaviest libraries to this list at my workplace and it's been really helpful at keeping startup times from regressing.
- phainopepla2 1y agoIt is annoying, but most linters will accept a `#noqa E402` comment to ignore it
- zahlman 1y ago>most linters will accept So, they agreed on a common system of linting error codes? Is that documented somewhere?