<div dir="ltr">Mypy would totally catch this. PEP 484 has specific words for whether imports are re-exported (they aren't unless you use 'as').<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 30, 2018 at 4:58 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, May 30, 2018 at 04:18:51AM +0000, Steve Barnes wrote:<br>
<br>
> Maybe what we need is to add a, possibly optional, or suppressible, <br>
> warning whenever the import system encounters an implicit/indirect <br>
> import?<br>
<br>
</span>I don't think your terminology ("implicit/indirect") is very accurate.<br>
<br>
    from os import errno<br>
<br>
is as explicit as you can get.<br>
<span class=""><br>
<br>
> If an import that is working because the package we are <br>
> importing it from has imported it from elsewhere, but it is not included <br>
> in the __init__ for that package,<br>
<br>
</span>I think you mean __all__ for the module.<br>
<br>
I'm not sure how that check would work. For a simple module, whenever <br>
you call "from module import name", the interpreter has to inspect the <br>
object it just imported, and if it is a module itself, check whether <br>
"name" is in the owning module's __all__.<br>
<br>
How would it work for packages? "from package import submodule" ought to <br>
work without a warning even if submodule isn't listed in __all__.<br>
<br>
Even for simple modules, it is prone to false positives: if "name" is <br>
documented as public, but not listed in __all__ then that would wrongly <br>
be detected as a non-public import.<br>
<br>
But most problematic, it does nothing about this case:<br>
<br>
    import os<br>
    os.errno<br>
<br>
I think this is best left for linters.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Steve<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>