New submission from Xiang Zhang <angwe...@126.com>: I see people wrongly write non-str objects in __all__ and the error message for this case is simply a AttributeError which doesn't reveal the cause directly.
>>> from test import * Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: attribute name must be string, not 'C' It would be better to make the cause more obvious, like importlib._bootstrap._handle_fromlist does: Traceback (most recent call last): File "/root/cpython/Lib/test/test_importlib/import_/test_fromlist.py", line 166, in test_invalid_type_in_all self.__import__('pkg', fromlist=['*']) File "/root/cpython/Lib/importlib/_bootstrap.py", line 1094, in __import__ return _handle_fromlist(module, fromlist, _gcd_import) File "/root/cpython/Lib/importlib/_bootstrap.py", line 1019, in _handle_fromlist recursive=True) File "/root/cpython/Lib/importlib/_bootstrap.py", line 1014, in _handle_fromlist raise TypeError(f"Item in {where} must be str, " TypeError: Item in pkg.__all__ must be str, not bytes ---------- components: Interpreter Core messages: 312704 nosy: xiang.zhang priority: normal severity: normal status: open title: better error message when __all__ contains non-str objects type: enhancement versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32932> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com