How to use collections.abc from both Python 3.8+ and Python 2.7

后端 未结 4 1811
执念已碎
执念已碎 2020-12-06 04:08

In Python 3.3 \"abstract base classes\" in collections (like MutableMapping or MutableSequence) were moved to second-level module

4条回答
  •  -上瘾入骨i
    2020-12-06 04:28

    I was getting error like this:

    C:\Users\gsc-30431\Anaconda3\lib\site-packages\unittest2\compatibility.py:148
      C:\Users\gsc-30431\Anaconda3\lib\site-packages\unittest2\compatibility.py:148: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is depr
    ecated since Python 3.3,and in 3.9 it will stop working
        class ChainMap(collections.MutableMapping):
    
    -- Docs: https://docs.pytest.org/en/latest/warnings.html
    

    SO i opened the File Compatibility.py by visiting the path showing in the error above! and Searched there the code where this Collections package is being used and Changed the previous line i.e:

    class ChainMap(collections.MutableMapping):
    

    to new Line:

    class ChainMap(collections.abc.MutableMapping):
    

    Screenshot:

    Just by adding .abc has solved my problem and i'm not getting warning anymore!

提交回复
热议问题