jit.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:toasted-marshmallow 作者: lyft 项目源码 文件源码
def inline(self, field, context):
        # type: (fields.Field, JitContext) -> Optional[str]
        """Generates a template for inlining string serialization.

        For example, generates "unicode(value) if value is not None else None"
        to serialize a string in Python 2.7
        """
        if is_overridden(field._serialize, fields.String._serialize):
            return None
        result = text_type.__name__ + '({0})'
        result += ' if {0} is not None else None'
        if not context.is_serializing:
            string_type_strings = ','.join([x.__name__ for x in string_types])
            result = ('(' + result + ') if '
                      '(isinstance({0}, (' + string_type_strings +
                      ')) or {0} is None) else dict()["error"]')
        return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号