Protobuf: Python deprecation warnings

Created on 10 Mar 2019  路  15Comments  路  Source: protocolbuffers/protobuf

Version: v3.7.0
Language: Python

C:\msys64\mingw64\lib\python3.7\site-packages\google\protobuf\internal\well_known_types.py:788: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is
deprecated, and in 3.8 it will stop working
  collections.MutableMapping.register(Struct)
C:\msys64\mingw64\lib\python3.7\site-packages\google\protobuf\internal\well_known_types.py:832: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is
deprecated, and in 3.8 it will stop working
python wait for 3.8.0 release

Most helpful comment

A fix is pending, why isn't it being merged? https://github.com/protocolbuffers/protobuf/pull/6272

All 15 comments

Thanks for raise it up. Will change the import in internal code to something like:

try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc

Expect to see the fix in future release.

@anandolee can I make a PR for this? If you're not working on this...

The fix is already submitted in internal. Thanks to willing provide PR

I got the following warnings with protobuf 3.7.0, the second of which is covered above.

In case it's not been done already, please could you also fix the first one? Thank you!

/usr/local/lib/python3.7/site-packages/google/protobuf/descriptor.py:47
  /usr/local/lib/python3.7/site-packages/google/protobuf/descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from google.protobuf.pyext import _message

/usr/local/lib/python3.7/site-packages/google/protobuf/internal/well_known_types.py:788
  /usr/local/lib/python3.7/site-packages/google/protobuf/internal/well_known_types.py:788: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    collections.MutableMapping.register(Struct)

Edit: also mentioned in https://github.com/protocolbuffers/protobuf/issues/5335#issuecomment-469623048.

I'm running 3.8.0, upgraded my generated python code etc. - and I'm still seeing this

/site-packages/google/protobuf/descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from google.protobuf.pyext import _message

Do I need to upgrade something else also?

I'm running 3.8.0, upgraded my generated python code etc. - and I'm still seeing this

/site-packages/google/protobuf/descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from google.protobuf.pyext import _message

Do I need to upgrade something else also?

I think https://github.com/protocolbuffers/protobuf/pull/6272 should fix this.

Python 3.8 is now in beta, with the final release due in October. I recommend also testing protobuf against Python 3.8.

https://www.python.org/dev/peps/pep-0569/

/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/google/protobuf/descriptor.py:47
  /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/google/protobuf/descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from google.protobuf.pyext import _message
/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/util/nest.py:1286
  /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/util/nest.py:1286: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    _pywrap_tensorflow.RegisterType("Mapping", _collections.Mapping)
/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/util/nest.py:1287
  /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/util/nest.py:1287: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    _pywrap_tensorflow.RegisterType("Sequence", _collections.Sequence)
/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/training/tracking/object_identity.py:61
  /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/training/tracking/object_identity.py:61: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    class ObjectIdentityDictionary(collections.MutableMapping):
/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/training/tracking/object_identity.py:112
  /home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/tensorflow/python/training/tracking/object_identity.py:112: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    class ObjectIdentitySet(collections.MutableSet):
-- Docs: https://docs.pytest.org/en/latest/warnings.html

Python 3.8 release candidate 1 is available: https://www.python.org/download/pre-releases

And Python 3.8.0 final is due out on Monday, 2019-10-14.

I've not checked them all, but looks fixed and released in latest Protocol Buffers v3.9.2:

https://github.com/protocolbuffers/protobuf/blob/a32c2d030674ad5913cbc6ac3f65f6bce2f688c2/python/google/protobuf/internal/well_known_types.py#L48-L53

Actually python/google/protobuf/descriptor.py when generated still contains such a import that pytest will still raise as a warning on.

Python 3.8 was released yesterday https://www.python.org/downloads/release/python-380/

A fix is pending, why isn't it being merged? https://github.com/protocolbuffers/protobuf/pull/6272

I'm also looking for a fix to

.venv\lib\site-packages\google\protobuf\descriptor.py:47
  c:\Users\masma\source\repos\orsteddcsmarketsanalytics\apps\portfolio_analytics\.venv\lib\site-packages\google\protobuf\descriptor.py:47: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from google.protobuf.pyext import _message

Im running v. 3.10.0 on python 3.7.4

$ pip show protobuf
Name: protobuf
Version: 3.10.0
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: None
Author-email: None
License: 3-Clause BSD License
Location: c:\users\masma\source\repos\orsteddcsmarketsanalytics\apps\portfolio_analytics\.venv\lib\site-packages
Requires: six, setuptools
Required-by: streamlit

https://bugs.python.org/issue37324 has been fixed so it's gone away from Python 3.9.

Python 3.9 development has started, with the first alpha due out in about a week (2019-11-18). I expect this might block core development soon.

Was this page helpful?
0 / 5 - 0 ratings