AttributeError: module 'collections' has no attribute 'Callable'
запускал у себя тест и вернуло вот такое
if isinstance(tests, collections.Callable) and not is_suite:
AttributeError: module 'collections' has no attribute 'Callable'
как это исправить? версия питона 3.10
Ответы (2 шт):
Начиная с Python 3.3 класс Callable (и некоторые другие классы) перенесены в модуль collections.abc, в модуле collections остались только псевдонимы ("ярлыки") для этих классов (для сохранения обратной совместимости со старым кодом), т.е. можно было импортировать тот же Callable как из collections, так и из collections.abc, см. https://docs.python.org/3/whatsnew/3.3.html#collections:
- The abstract base classes have been moved in a new collections.abc module, to better differentiate between the abstract and the concrete collections classes. Aliases for ABCs are still present in the collections module to preserve existing imports. (bpo-11085)
В Python 3.9 эти псевдонимы были сделаны deprecated (не рекомендуемые к использованию), см. https://docs.python.org/3/whatsnew/3.9.html#you-should-check-for-deprecationwarning-in-your-code, а в версии Python 3.10 - удалены см. https://docs.python.org/3/whatsnew/3.10.html#removed:
- Remove deprecated aliases to Collections Abstract Base Classes from the collections module. (Contributed by Victor Stinner in bpo-37324.)
Поэтому Callable теперь нужно импортировать из collections.abc:
from collections.abc import Callable
...
if isinstance(tests, Callable) and not is_suite:
...