Fix Python 3.10 C++ tests (#9128)

The first change is to make sure we always define PY_SSIZE_T_CLEAN
before including Python.h. Starting from Python 3.10 this is required.
Otherwise we get errors like this:

SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

The second change is to update reflection_test.py to account for the
fact that with Python 3.10, we get a TypeError even with the C++
implementation when trying to assign a float to a bool field. I'm not
sure why this changed with Python 3.10, but it seems like a good thing
since this is the desired behavior anyway.
pull/9133/head
Adam Cozzette 3 years ago committed by GitHub
parent d08bc71c96
commit 63f952b987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      python/google/protobuf/internal/api_implementation.cc
  2. 4
      python/google/protobuf/internal/reflection_test.py
  3. 1
      python/google/protobuf/proto_api.h
  4. 1
      python/google/protobuf/pyext/descriptor.cc
  5. 1
      python/google/protobuf/pyext/descriptor.h
  6. 1
      python/google/protobuf/pyext/descriptor_containers.cc
  7. 1
      python/google/protobuf/pyext/descriptor_containers.h
  8. 1
      python/google/protobuf/pyext/descriptor_database.h
  9. 1
      python/google/protobuf/pyext/descriptor_pool.cc
  10. 1
      python/google/protobuf/pyext/descriptor_pool.h
  11. 1
      python/google/protobuf/pyext/extension_dict.h
  12. 1
      python/google/protobuf/pyext/field.h
  13. 1
      python/google/protobuf/pyext/map_container.h
  14. 1
      python/google/protobuf/pyext/message.h
  15. 1
      python/google/protobuf/pyext/message_factory.cc
  16. 1
      python/google/protobuf/pyext/message_factory.h
  17. 1
      python/google/protobuf/pyext/message_module.cc
  18. 1
      python/google/protobuf/pyext/repeated_composite_container.h
  19. 1
      python/google/protobuf/pyext/repeated_scalar_container.h
  20. 1
      python/google/protobuf/pyext/scoped_pyobject_ptr.h
  21. 1
      python/google/protobuf/pyext/unknown_fields.cc
  22. 1
      python/google/protobuf/pyext/unknown_fields.h
  23. 1
      python/google/protobuf/python_protobuf.h

@ -28,6 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {

@ -37,6 +37,7 @@ import copy
import gc
import operator
import struct
import sys
import warnings
import unittest
@ -376,7 +377,8 @@ class ReflectionTest(unittest.TestCase):
self.assertRaises(TypeError, setattr, proto, 'optional_float', 'foo')
self.assertRaises(TypeError, setattr, proto, 'optional_double', 'foo')
# TODO(jieluo): Fix type checking difference for python and c extension
if api_implementation.Type() == 'python':
if (api_implementation.Type() == 'python' or
(sys.version_info.major, sys.version_info.minor) >= (3, 10)):
self.assertRaises(TypeError, setattr, proto, 'optional_bool', 1.1)
else:
proto.optional_bool = 1.1

@ -45,6 +45,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
#define GOOGLE_PROTOBUF_PYTHON_PROTO_API_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/descriptor_database.h>

@ -32,6 +32,7 @@
#include <google/protobuf/pyext/descriptor.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <frameobject.h>

@ -33,6 +33,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/descriptor.h>

@ -49,6 +49,7 @@
// because the Python API is based on C, and does not play well with C++
// inheritance.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/descriptor.h>

@ -34,6 +34,7 @@
// Mappings and Sequences of descriptors.
// They implement containers like fields_by_name, EnumDescriptor.values...
// See descriptor_containers.cc for more description.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_DATABASE_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/descriptor_database.h>

@ -32,6 +32,7 @@
#include <unordered_map>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/descriptor.pb.h>

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <unordered_map>

@ -34,6 +34,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <memory>

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <cstdint>

@ -34,6 +34,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <cstdint>

@ -30,6 +30,7 @@
#include <unordered_map>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/dynamic_message.h>

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <unordered_map>

@ -28,6 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <google/protobuf/message_lite.h>

@ -34,6 +34,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_COMPOSITE_CONTAINER_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <memory>

@ -34,6 +34,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_REPEATED_SCALAR_CONTAINER_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <memory>

@ -35,6 +35,7 @@
#include <google/protobuf/stubs/common.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {
namespace protobuf {

@ -30,6 +30,7 @@
#include <google/protobuf/pyext/unknown_fields.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <set>
#include <memory>

@ -31,6 +31,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_UNKNOWN_FIELDS_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <memory>

@ -36,6 +36,7 @@
#ifndef GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__
#define GOOGLE_PROTOBUF_PYTHON_PYTHON_PROTOBUF_H__
#define PY_SSIZE_T_CLEAN
#include <Python.h>
namespace google {

Loading…
Cancel
Save