From b2c1fe77b4a5fda45669b200ca455c862b8e30e7 Mon Sep 17 00:00:00 2001 From: Sanchali torpe Date: Fri, 30 Jan 2026 05:17:25 -0800 Subject: [PATCH] Add warning for EventSendPort without matching OutputEvent --- .../visitors/validators/general.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/nineml/abstraction/componentclass/visitors/validators/general.py b/nineml/abstraction/componentclass/visitors/validators/general.py index ee671212..18fa0741 100644 --- a/nineml/abstraction/componentclass/visitors/validators/general.py +++ b/nineml/abstraction/componentclass/visitors/validators/general.py @@ -16,6 +16,9 @@ from sympy.logic.boolalg import BooleanTrue, BooleanFalse from nineml.visitors import BaseVisitor, BaseVisitorWithContext from functools import reduce +import warnings +from nineml.abstraction.componentclass.ports import EventSendPort + class AliasesAreNotRecursiveComponentValidator(BaseVisitor): @@ -371,3 +374,31 @@ def action_alias(self, alias, **kwargs): # @UnusedVariable def default_action(self, obj, nineml_cls, **kwargs): pass + + class EventSendPortHasOutputEventComponentValidator(BaseVisitorWithContext): + """ + Warn if an EventSendPort has no matching OutputEvent + """ + + def __init__(self, component_class, **kwargs): # @UnusedVariable + BaseVisitorWithContext.__init__(self) + self.component_class = component_class + self.visit(component_class) + + def action_eventsendport(self, port, **kwargs): # @UnusedVariable + # Check for matching OutputEvent by name + matches = [ + ev for ev in self.component_class.output_events + if ev.name == port.name + ] + + if not matches: + warnings.warn( + "EventSendPort '{}' has no matching OutputEvent" + .format(port.name), + UserWarning + ) + + def default_action(self, obj, nineml_cls, **kwargs): + pass +