[issue35358] avoid '-' in importlib.import_module and builtins.__import__

Serhiy Storchaka report at bugs.python.org
Fri Nov 30 04:09:23 EST 2018


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

'-' is not special. The import statement requires the module name been an identifier. This is just a requirement of Python syntax. But when pass the module name as a string, there is no such limitation in CPython. This is like an attribute name or keyword argument name should be identifiers in expressions, but you can pass an arbitrary string to getattr() and use a dict with arbitrary string keys as kwargs. Currently non-identifier strings are accepted, but this is an implementation detail, not a part of the language.

There are reasons against adding additional checks for attribute names and keyword argument names. This will slow down execution of all code. This is less critical for importing, because it is slower than attribute access and function call. But on other side, the benefit of adding this check is not obvious.

It may be worth to discuss this on mailing lists. First read previous discussions about attribute names and keyword argument names.

----------
nosy: +brett.cannon, eric.snow, gvanrossum, ncoghlan, serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35358>
_______________________________________


More information about the Python-bugs-list mailing list