[Python-ideas] Was `os.errno` undocumented?

Steven D'Aprano steve at pearwood.info
Wed May 30 07:58:52 EDT 2018

On Wed, May 30, 2018 at 04:18:51AM +0000, Steve Barnes wrote:

> Maybe what we need is to add a, possibly optional, or suppressible, 
> warning whenever the import system encounters an implicit/indirect 
> import?

I don't think your terminology ("implicit/indirect") is very accurate.

    from os import errno

is as explicit as you can get.

> If an import that is working because the package we are 
> importing it from has imported it from elsewhere, but it is not included 
> in the __init__ for that package,

I think you mean __all__ for the module.

I'm not sure how that check would work. For a simple module, whenever 
you call "from module import name", the interpreter has to inspect the 
object it just imported, and if it is a module itself, check whether 
"name" is in the owning module's __all__.

How would it work for packages? "from package import submodule" ought to 
work without a warning even if submodule isn't listed in __all__.

Even for simple modules, it is prone to false positives: if "name" is 
documented as public, but not listed in __all__ then that would wrongly 
be detected as a non-public import.

But most problematic, it does nothing about this case:

    import os

I think this is best left for linters.


More information about the Python-ideas mailing list