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

Guido van Rossum guido at python.org
Wed May 30 11:12:15 EDT 2018


Mypy would totally catch this. PEP 484 has specific words for whether
imports are re-exported (they aren't unless you use 'as').

On Wed, May 30, 2018 at 4:58 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> 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
>     os.errno
>
> I think this is best left for linters.
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180530/dad18929/attachment-0001.html>


More information about the Python-ideas mailing list