Author xiang.zhang
Recipients xiang.zhang
Date 2018-02-24.08:51:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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_/", line 166, in test_invalid_type_in_all
    self.__import__('pkg', fromlist=['*'])
  File "/root/cpython/Lib/importlib/", line 1094, in __import__
    return _handle_fromlist(module, fromlist, _gcd_import)
  File "/root/cpython/Lib/importlib/", line 1019, in _handle_fromlist
  File "/root/cpython/Lib/importlib/", line 1014, in _handle_fromlist
    raise TypeError(f"Item in {where} must be str, "
TypeError: Item in pkg.__all__ must be str, not bytes
Date User Action Args
2018-02-24 08:51:48xiang.zhangsetrecipients: + xiang.zhang
2018-02-24 08:51:48xiang.zhangsetmessageid: <>
2018-02-24 08:51:48xiang.zhanglinkissue32932 messages
2018-02-24 08:51:47xiang.zhangcreate