Explorar el Código

Import MutableSequence from collections.abc on Python 3. (#6272)

Fixes https://github.com/protocolbuffers/protobuf/issues/5335.
Benjamin Peterson hace 5 años
padre
commit
9d61eada0f
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. 5 1
      python/google/protobuf/pyext/message.cc

+ 5 - 1
python/google/protobuf/pyext/message.cc

@@ -2958,8 +2958,12 @@ bool InitProto2MessageModule(PyObject *m) {
         reinterpret_cast<PyObject*>(
         reinterpret_cast<PyObject*>(
             &RepeatedCompositeContainer_Type));
             &RepeatedCompositeContainer_Type));
 
 
-    // Register them as collections.Sequence
+    // Register them as MutableSequence.
+#if PY_MAJOR_VERSION >= 3
+    ScopedPyObjectPtr collections(PyImport_ImportModule("collections.abc"));
+#else
     ScopedPyObjectPtr collections(PyImport_ImportModule("collections"));
     ScopedPyObjectPtr collections(PyImport_ImportModule("collections"));
+#endif
     if (collections == NULL) {
     if (collections == NULL) {
       return false;
       return false;
     }
     }