[gobject-introspection/ebassi/signal-emitter: 59/59] scanner: Validate emitter methods
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/ebassi/signal-emitter: 59/59] scanner: Validate emitter methods
- Date: Sat, 12 Feb 2022 15:27:39 +0000 (UTC)
commit e9956657be16c102a57443e474a5206756e40548
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Jun 24 18:00:02 2021 +0100
scanner: Validate emitter methods
Follow the same semantics as Vala:
1. emitters should have the same return value as the signal
2. emitters should have the same parameters as the signal they
emit (minus the instance parameter, which is implied in
signals)
giscanner/introspectablepass.py | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
---
diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py
index 3bb6429a..419c3d7e 100644
--- a/giscanner/introspectablepass.py
+++ b/giscanner/introspectablepass.py
@@ -209,6 +209,41 @@ class IntrospectablePass(object):
if not self._type_is_introspectable(obj.retval.type):
obj.introspectable = False
return True
+ if isinstance(obj, ast.Signal):
+ if obj.emitter is None:
+ return False
+ parent = stack[0]
+ for method in parent.methods:
+ if method.name != obj.emitter:
+ continue
+ if not obj.retval.type.is_equiv(method.retval.type):
+ self._parameter_warning(
+ parent,
+ obj,
+ "Emitter method %s for signal %s::%s does not have the "
+ "same return value type" % (method.symbol, parent.name, obj.name))
+ obj.emitter = None
+ return False
+ n_emitter_params = len(method.parameters)
+ n_signal_params = len(obj.parameters)
+ if n_emitter_params != n_signal_params:
+ self._parameter_warning(
+ parent,
+ obj,
+ "Emitter method %s for signal %s::%s does not have the "
+ "same number of arguments (expected: %d)" % (method.symbol, parent.name, obj.name,
n_signal_params))
+ obj.emitter = None
+ return False
+ for idx, signal_param in enumerate(obj.parameters):
+ method_param = method.parameters[idx + 1]
+ if signal_param.type.is_equiv(method_param.type):
+ self._parameter_warning(
+ parent,
+ obj,
+ "Emitter method %s for signal %s::%s does not have the "
+ "same type of arguments" % (method.symbol, parent.name, obj.name))
+ obj.emitter = None
+ return False
return True
def _introspectable_property_analysis(self, obj, stack):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]