Sync from Piper @401883098

PROTOBUF_SYNC_PIPER
diff --git a/python/MANIFEST.in b/python/MANIFEST.in
index 5fb0192..a81760f 100644
--- a/python/MANIFEST.in
+++ b/python/MANIFEST.in
@@ -15,3 +15,5 @@
 global-exclude *.pyc
 global-exclude *.pyo
 global-exclude *.so
+
+include LICENSE
diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py
index 496df6a..b8122e8 100644
--- a/python/google/protobuf/__init__.py
+++ b/python/google/protobuf/__init__.py
@@ -30,4 +30,4 @@
 
 # Copyright 2007 Google Inc. All Rights Reserved.
 
-__version__ = '3.17.3'
+__version__ = '3.18.1'
diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py
index 0f7bd17..61c242f 100644
--- a/python/google/protobuf/descriptor.py
+++ b/python/google/protobuf/descriptor.py
@@ -951,7 +951,7 @@
     public_dependencies (list[FileDescriptor]): A subset of
       :attr:`dependencies`, which were declared as "public".
     message_types_by_name (dict(str, Descriptor)): Mapping from message names
-      to their :class:`Desctiptor`.
+      to their :class:`Descriptor`.
     enum_types_by_name (dict(str, EnumDescriptor)): Mapping from enum names to
       their :class:`EnumDescriptor`.
     extensions_by_name (dict(str, FieldDescriptor)): Mapping from extension
diff --git a/python/google/protobuf/internal/api_implementation.py b/python/google/protobuf/internal/api_implementation.py
index a366731..7fef237 100644
--- a/python/google/protobuf/internal/api_implementation.py
+++ b/python/google/protobuf/internal/api_implementation.py
@@ -41,46 +41,15 @@
   # The compile-time constants in the _api_implementation module can be used to
   # switch to a certain implementation of the Python API at build time.
   _api_version = _api_implementation.api_version
-  _proto_extension_modules_exist_in_build = True
 except ImportError:
   _api_version = -1  # Unspecified by compiler flags.
-  _proto_extension_modules_exist_in_build = False
 
 if _api_version == 1:
   raise ValueError('api_version=1 is no longer supported.')
-if _api_version < 0:  # Still unspecified?
-  try:
-    # The presence of this module in a build allows the proto implementation to
-    # be upgraded merely via build deps rather than a compiler flag or the
-    # runtime environment variable.
-    # pylint: disable=g-import-not-at-top
-    from google.protobuf import _use_fast_cpp_protos
-    # Work around a known issue in the classic bootstrap .par import hook.
-    if not _use_fast_cpp_protos:
-      raise ImportError('_use_fast_cpp_protos import succeeded but was None')
-    del _use_fast_cpp_protos
-    _api_version = 2
-    from google.protobuf import use_pure_python
-    raise RuntimeError(
-        'Conflicting deps on both :use_fast_cpp_protos and :use_pure_python.\n'
-        ' go/build_deps_on_BOTH_use_fast_cpp_protos_AND_use_pure_python\n'
-        'This should be impossible via a link error at build time...')
-  except ImportError:
-    try:
-      # pylint: disable=g-import-not-at-top
-      from google.protobuf import use_pure_python
-      del use_pure_python  # Avoids a pylint error and namespace pollution.
-      _api_version = 0
-    except ImportError:
-      # TODO(b/74017912): It's unsafe to enable :use_fast_cpp_protos by default;
-      # it can cause data loss if you have any Python-only extensions to any
-      # message passed back and forth with C++ code.
-      #
-      # TODO(b/17427486): Once that bug is fixed, we want to make both Python 2
-      # and Python 3 default to `_api_version = 2` (C++ implementation V2).
-      pass
 
-_default_implementation_type = ('python' if _api_version <= 0 else 'cpp')
+
+_default_implementation_type = ('cpp' if _api_version > 0 else 'python')
+
 
 # This environment variable can be used to switch to a certain implementation
 # of the Python API, overriding the compile-time constants in the
@@ -97,21 +66,6 @@
                 'Falling back to the python implementation.')
   _implementation_type = 'python'
 
-# This environment variable can be used to switch between the two
-# 'cpp' implementations, overriding the compile-time constants in the
-# _api_implementation module. Right now only '2' is supported. Any other
-# value will cause an error to be raised.
-_implementation_version_str = os.getenv(
-    'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION', '2')
-
-if _implementation_version_str != '2':
-  raise ValueError(
-      'unsupported PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION: "' +
-      _implementation_version_str + '" (supported versions: 2)'
-      )
-
-_implementation_version = int(_implementation_version_str)
-
 
 # Detect if serialization should be deterministic by default
 try:
@@ -150,7 +104,7 @@
 
 # See comment on 'Type' above.
 def Version():
-  return _implementation_version
+  return 2
 
 
 # For internal use only
diff --git a/python/google/protobuf/message.py b/python/google/protobuf/message.py
index 224d2fc..ee46d0e 100644
--- a/python/google/protobuf/message.py
+++ b/python/google/protobuf/message.py
@@ -359,6 +359,14 @@
     """
     raise NotImplementedError
 
+  @classmethod
+  def FromString(cls, s):
+    raise NotImplementedError
+
+  @staticmethod
+  def RegisterExtension(extension_handle):
+    raise NotImplementedError
+
   def _SetListener(self, message_listener):
     """Internal method used by the protocol message implementation.
     Clients should not call this directly.
diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc
index 4340afc..cb48faa 100644
--- a/python/google/protobuf/pyext/message.cc
+++ b/python/google/protobuf/pyext/message.cc
@@ -1919,7 +1919,9 @@
   // explicit in our correctness checks.
   if (ptr == nullptr || ctx.BytesUntilLimit(ptr) < 0) {
     // Parse error or the parser overshoot the limit.
-    PyErr_Format(DecodeError_class, "Error parsing message");
+    PyErr_Format(
+        DecodeError_class, "Error parsing message with type '%s'",
+        self->GetMessageClass()->message_descriptor->full_name().c_str());
     return NULL;
   }
   // ctx has an explicit limit set (length of string_view), so we have to
diff --git a/python/release.sh b/python/release.sh
index 8ec6e11..15a70db 100755
--- a/python/release.sh
+++ b/python/release.sh
@@ -73,6 +73,9 @@
   sed -i -r "s/__version__ = '.*'/__version__ = '${VERSION}.${DEV}'/" python/google/protobuf/__init__.py
 fi
 
+# Copy LICENSE
+cp LICENSE python/LICENSE
+
 cd python
 
 # Run tests locally.
diff --git a/python/setup.py b/python/setup.py
index 7b5ea23..ab42b6f 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -211,11 +211,11 @@
     extra_compile_args = []
 
     if sys.platform != 'win32':
-        extra_compile_args.append('-Wno-write-strings')
-        extra_compile_args.append('-Wno-invalid-offsetof')
-        extra_compile_args.append('-Wno-sign-compare')
-        extra_compile_args.append('-Wno-unused-variable')
-        extra_compile_args.append('-std=c++11')
+      extra_compile_args.append('-Wno-write-strings')
+      extra_compile_args.append('-Wno-invalid-offsetof')
+      extra_compile_args.append('-Wno-sign-compare')
+      extra_compile_args.append('-Wno-unused-variable')
+      extra_compile_args.append('-std=c++11')
 
     if sys.platform == 'darwin':
       extra_compile_args.append("-Wno-shorten-64-to-32");
@@ -285,21 +285,20 @@
       maintainer_email='protobuf@googlegroups.com',
       license='3-Clause BSD License',
       classifiers=[
-        "Programming Language :: Python",
-        "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.3",
-        "Programming Language :: Python :: 3.4",
-        "Programming Language :: Python :: 3.5",
-        "Programming Language :: Python :: 3.6",
-        "Programming Language :: Python :: 3.7",
-        ],
+          "Programming Language :: Python",
+          "Programming Language :: Python :: 3",
+          "Programming Language :: Python :: 3.3",
+          "Programming Language :: Python :: 3.4",
+          "Programming Language :: Python :: 3.5",
+          "Programming Language :: Python :: 3.6",
+          "Programming Language :: Python :: 3.7",
+      ],
       namespace_packages=['google'],
       packages=find_packages(
           exclude=[
               'import_test_package',
               'protobuf_distutils',
-          ],
-      ),
+          ],),
       test_suite='google.protobuf.internal',
       cmdclass={
           'clean': clean,
@@ -309,4 +308,5 @@
       },
       install_requires=install_requires,
       ext_modules=ext_module_list,
+      python_requires=">=3.5",
   )