[PATCHES] reduce unnecessary imports in Python

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Wed Oct 24 23:05:52 UTC 2018


This is a very boring set of patches.

In Python code we tend to import a lot of unnecessary modules. This sort
of doesn't really matter, in that it just wastes time and memory and
obfuscates what is really going on. Only sometimes will it cause a real bug.

Since each individual unused import is such a tiny injury, it can feel
silly to start fixing them, and after a short while that is indeed how I
felt. This patchset is a measure of how far I got -- there are perhaps
thousands more.

It is difficult to know whether a python import is truly useless, as the
import can have side-effects, deliberate or not. For example, "import
samba.dckeytab" intentionally (and solely) has the effect of changing
the behaviour of samba.net. This change is global, so if you import a
module that somewhere imports samba.dckeytab, your samba.net.Net will
change. It is lucky therefore that this patchset passes CI:

https://gitlab.com/samba-team/devel/samba/pipelines/34120340

To make things more interesting, a few of the patches introduce NEW
imports, because it turns out we needed them.

Douglas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: imports.patch
Type: text/x-patch
Size: 39992 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20181025/466f5e8e/imports.bin>


More information about the samba-technical mailing list