Importing a module does not import all its imports by default. You do need to import functions
in s1
and s2
even if you are already doing import x
.
Or alternatively, you could do from x import functions
inside s1
and s2
. But personally I'm not sure if I would ever do that - it obfuscates things a bit, and one might say that code duplication is not a thing in the case of imports. Maybe it would make sense on a conceptual level: we import functions
via x
because the functions are specific to x
. But in such case I would make x
a package and put functions
in that package (in which case the import
statement would incidentally look the same). But if functions
is not specific to x
, i.e. it is expected to be useful for various modules unrelated to x
, then don't import it via x
.
If you're concerned about the performance impact of multiple imports, this explains that there is none.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…