Merge "Fix 'method object has no attribute __yaql_function__' on py3"

This commit is contained in:
Zuul 2020-11-05 06:57:03 +00:00 committed by Gerrit Code Review
commit 1558b8dc52
3 changed files with 19 additions and 2 deletions

View File

@ -613,8 +613,8 @@ def assemble_object_definition(parsed, model_format=dsl_types.DumpTypes.Mixed):
def function(c):
if hasattr(c, 'im_func'):
return c.im_func
if hasattr(c, '__func__'):
return c.__func__
return c

View File

@ -13,6 +13,7 @@
import copy
import semantic_version
import types
from unittest import mock
import weakref
@ -232,6 +233,18 @@ class TestDSLHelpers(base.MuranoTestCase):
test_parsed, None)
self.assertEqual('Invalid Serialization Type', str(e))
def test_function(self):
def f():
return
self.assertTrue(isinstance(helpers.function(f), types.FunctionType))
def test_function_from_method(self):
class C:
def m(self):
return
c = C()
self.assertTrue(isinstance(helpers.function(c.m), types.FunctionType))
def test_weak_proxy(self):
self.assertIsNone(helpers.weak_proxy(None))

View File

@ -0,0 +1,4 @@
---
fixes:
- Avoid the `'method' object has no attribute '__yaql_function__'` error
when calling some YAQL functions with Python 3