"In 3.8 it will stop working": collections import has moved
nedbat opened this issue · 5 comments
nedbat commented
When I run my coverage.py test suite under Python 3.7, I see this:
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:19: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Container', ist(collections.Container))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:21: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Iterable', ist(collections.Iterable))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:23: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Hashable', ist(collections.Hashable))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:27: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Iterator', ist(collections.Iterator))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:28: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Sized', ist(collections.Sized))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:29: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Callable', ist(collections.Callable))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:30: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Sequence', ist(collections.Sequence))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:31: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Set', ist(collections.Set))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:32: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('MutableSequence', ist(collections.MutableSequence))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:33: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('MutableSet', ist(collections.MutableSet))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:34: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('Mapping', ist(collections.Mapping))
/Users/ned/coverage/v4.5.x/.tox/py37/lib/python3.7/site-packages/contracts/library/miscellaneous_aliases.py:35: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
m_new_contract('MutableMapping', ist(collections.MutableMapping))
nedbat commented
This is now broken on Python 3.9:
coverage/misc.py:60: in <module>
from contracts import contract # pylint: disable=unused-import
.tox/py39/lib/python3.9/site-packages/contracts/__init__.py:44: in <module>
from .useful_contracts import *
.tox/py39/lib/python3.9/site-packages/contracts/useful_contracts/__init__.py:10: in <module>
from .numbers import *
.tox/py39/lib/python3.9/site-packages/contracts/useful_contracts/numbers.py:8: in <module>
new_contract('float', 'Float')
.tox/py39/lib/python3.9/site-packages/contracts/main.py:558: in new_contract
return new_contract_impl(*args)
.tox/py39/lib/python3.9/site-packages/contracts/main.py:563: in new_contract_impl
from .syntax import ParseException
.tox/py39/lib/python3.9/site-packages/contracts/syntax.py:91: in <module>
from .library import (EqualTo, Unary, Binary, composite_contract,
.tox/py39/lib/python3.9/site-packages/contracts/library/__init__.py:38: in <module>
from .miscellaneous_aliases import *
.tox/py39/lib/python3.9/site-packages/contracts/library/miscellaneous_aliases.py:19: in <module>
m_new_contract('Container', ist(collections.Container))
E AttributeError: module 'collections' has no attribute 'Container'
simongarisch commented
Importing ABCs from collections rather than collections.abc will stop working in 3.9.
However, it's also worth noting that 3.9 is still in testing.
(py38) C:\WINDOWS\System32>python
Python 3.8.3 (default, May 19 2020, 06:50:17) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import Container
<stdin>:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
As for what this includes...
>>> dir(abc)
['AsyncGenerator', 'AsyncIterable', 'AsyncIterator', 'Awaitable', 'ByteString', 'Callable', 'Collection', 'Container', 'Coroutine', 'Generator', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'Reversible', 'Sequence', 'Set', 'Sized', 'ValuesView',
nedbat commented
I'm not sure what your point is about "3.9 is still in testing." Do you think by 3.9 final they will change their mind and this problem won't need to be fixed? This should be fixed now, so that people preparing for 3.9 can use this library as part of their testing strategy.
simongarisch commented
I agree. It should be fixed. #84 should to the trick. @AndreaCensi let us know if you are happy with PR #84.