You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by tv...@apache.org on 2020/01/02 23:35:14 UTC

[beam] branch master updated: Catch __module__ is None.

This is an automated email from the ASF dual-hosted git repository.

tvalentyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ac760a  Catch __module__ is None.
     new ad7f6e1  Merge pull request #10475 from rainwoodman/patch-1
0ac760a is described below

commit 0ac760ae5b7ae874d00c0c39d973563be02775c5
Author: Yu Feng <ra...@gmail.com>
AuthorDate: Fri Dec 27 15:18:43 2019 -0800

    Catch __module__ is None.
    
    The current code crashes when __module__ is None.
    
    According to https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy
    __module__ is  "The name of the module the function was defined in, or None if unavailable."
    
    As a very particular example, Protobuf sets generated type's __module__ to None:
      https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/message_factory.py#L85
---
 sdks/python/apache_beam/internal/pickler.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sdks/python/apache_beam/internal/pickler.py b/sdks/python/apache_beam/internal/pickler.py
index 3cca9d3..0296840 100644
--- a/sdks/python/apache_beam/internal/pickler.py
+++ b/sdks/python/apache_beam/internal/pickler.py
@@ -75,6 +75,7 @@ if not getattr(dill, '_dill', None):
 def _is_nested_class(cls):
   """Returns true if argument is a class object that appears to be nested."""
   return (isinstance(cls, type)
+          and cls.__module__ is not None
           and cls.__module__ != 'builtins'     # Python 3
           and cls.__module__ != '__builtin__'  # Python 2
           and cls.__name__ not in sys.modules[cls.__module__].__dict__)