Handling of ephemeral methods was fixed
Ephemeral method is the one that created on the fly and doesn't belong to extension class. Such methods were returned as a replacement for ambiguous methods. Such ephemeral method would throw exception upon attempt to invoke it so that we get this exception on run-time rather that load-time. However yaql FunctionDefinition code wasn't ready for such functions Change-Id: Ica8585b9750277d29f571b90dc7b92e12e5fef30 Closes-Bug: #1562011
This commit is contained in:
parent
5c3f6b205d
commit
9dba63ed80
@ -36,20 +36,22 @@ virtual_exceptions.register()
|
||||
|
||||
|
||||
class MuranoMethod(dsl_types.MuranoMethod, meta.MetaProvider):
|
||||
def __init__(self, declaring_type, name, payload, original_name=None):
|
||||
def __init__(self, declaring_type, name, payload, original_name=None,
|
||||
ephemeral=False):
|
||||
self._name = name
|
||||
original_name = original_name or name
|
||||
self._declaring_type = weakref.ref(declaring_type)
|
||||
self._meta_values = None
|
||||
self_ref = self if ephemeral else weakref.proxy(self)
|
||||
|
||||
if callable(payload):
|
||||
if isinstance(payload, specs.FunctionDefinition):
|
||||
self._body = payload
|
||||
else:
|
||||
self._body = yaql_integration.get_function_definition(
|
||||
payload, weakref.proxy(self), original_name)
|
||||
payload, self_ref, original_name)
|
||||
self._arguments_scheme = None
|
||||
if any((
|
||||
if declaring_type.extension_class and any((
|
||||
helpers.inspect_is_static(
|
||||
declaring_type.extension_class, original_name),
|
||||
helpers.inspect_is_classmethod(
|
||||
@ -96,8 +98,7 @@ class MuranoMethod(dsl_types.MuranoMethod, meta.MetaProvider):
|
||||
declaring_type)
|
||||
|
||||
self._instance_stub, self._static_stub = \
|
||||
yaql_integration.build_stub_function_definitions(
|
||||
weakref.proxy(self))
|
||||
yaql_integration.build_stub_function_definitions(self_ref)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -250,7 +250,8 @@ class MuranoClass(dsl_types.MuranoClass, MuranoType, dslmeta.MetaProvider):
|
||||
except exceptions.AmbiguousMethodName as e:
|
||||
def func(*args, **kwargs):
|
||||
raise e
|
||||
yield murano_method.MuranoMethod(self, name, func)
|
||||
yield murano_method.MuranoMethod(
|
||||
self, name, func, ephemeral=True)
|
||||
|
||||
def find_single_property(self, name):
|
||||
result = self.find_property(name)
|
||||
|
@ -152,11 +152,12 @@ def _infer_parameter_type(name, class_name):
|
||||
|
||||
|
||||
def get_function_definition(func, murano_method, original_name):
|
||||
param_type_func = lambda name: _infer_parameter_type(
|
||||
name, cls.__name__)
|
||||
body = func
|
||||
cls = murano_method.declaring_type.extension_class
|
||||
if (helpers.inspect_is_method(cls, original_name) or
|
||||
param_type_func = \
|
||||
lambda name: None if not cls else _infer_parameter_type(
|
||||
name, cls.__name__)
|
||||
body = func
|
||||
if (cls is None or helpers.inspect_is_method(cls, original_name) or
|
||||
helpers.inspect_is_classmethod(cls, original_name)):
|
||||
body = helpers.function(func)
|
||||
fd = specs.get_function_definition(
|
||||
@ -164,12 +165,12 @@ def get_function_definition(func, murano_method, original_name):
|
||||
parameter_type_func=param_type_func)
|
||||
fd.is_method = True
|
||||
fd.is_function = False
|
||||
if helpers.inspect_is_method(cls, original_name):
|
||||
if not cls or helpers.inspect_is_method(cls, original_name):
|
||||
fd.set_parameter(
|
||||
0,
|
||||
dsl.MuranoObjectParameter(murano_method.declaring_type),
|
||||
overwrite=True)
|
||||
if helpers.inspect_is_classmethod(cls, original_name):
|
||||
if cls and helpers.inspect_is_classmethod(cls, original_name):
|
||||
_remove_first_parameter(fd)
|
||||
body = func
|
||||
name = getattr(func, '__murano_name', None)
|
||||
@ -177,8 +178,9 @@ def get_function_definition(func, murano_method, original_name):
|
||||
fd.name = name
|
||||
fd.insert_parameter(specs.ParameterDefinition(
|
||||
'?1', yaqltypes.Context(), 0))
|
||||
is_static = (helpers.inspect_is_static(cls, original_name) or
|
||||
helpers.inspect_is_classmethod(cls, original_name))
|
||||
is_static = cls and (
|
||||
helpers.inspect_is_static(cls, original_name) or
|
||||
helpers.inspect_is_classmethod(cls, original_name))
|
||||
if is_static:
|
||||
fd.insert_parameter(specs.ParameterDefinition(
|
||||
'?2', yaqltypes.PythonType(object), 1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user