[Python-ideas] New use for the 'in' keyword.

Simon simon.bordeyne at gmail.com
Sun Mar 10 18:01:46 EDT 2019


Python's 'in' keyword has already several use cases, whether it's for
testing inclusion in a set, or to iterate over that set, nevertheless, I
think we could add one more function to that keyword.

It's not uncommon to see star imports in some sources. The reason that
people use star imports are mainly the following :

- ease of use of the module's function
- overwriting parts of a module with another module's similarly named
functions.

Obviously, there are plenty of cases where you don't want your module's
functions to be overwritten, but sometimes, you do. I'm suggesting that the
in keyword would be used to import a module in another module's namespace,
with the following syntax :

import numpy as np
import math in np

This has two advantages over star imports :

1/ You keep a namespace. For maintainability reasons, it's best to use
namespaces
2/ You can overwrite parts of a module with another one
3/ IDEs would know which modules have been imported and which functions are
defined there, which they can't have with star imports.

Additionnally, The following syntax would also be valid :

import math
import numpy in math
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190310/fdf63c65/attachment.html>


More information about the Python-ideas mailing list