Author xiang.zhang
Recipients xiang.zhang
Date 2018-02-24.08:51:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519462308.25.0.467229070634.issue32932@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-02-24 08:51:48xiang.zhangsetrecipients: + xiang.zhang
2018-02-24 08:51:48xiang.zhangsetmessageid: <1519462308.25.0.467229070634.issue32932@psf.upfronthosting.co.za>
2018-02-24 08:51:48xiang.zhanglinkissue32932 messages
2018-02-24 08:51:47xiang.zhangcreate