Skip to content

Commit

Permalink
prevent event hanlders for events with the same name as switches
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Jun 19, 2020
1 parent 8a79574 commit 87b61e0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mpf/core/events.py
Expand Up @@ -153,13 +153,16 @@ def add_handler(self, event: str, handler: Any, priority: int = 1, blocking_faci
for handler in handler_list:
``events.remove_handler(my_handler)``
"""
if event is None:
raise AssertionError("Cannot pass event None.")
if not self.machine.options['production']:
if event is None:
raise AssertionError("Cannot pass event None.")
if hasattr(self.machine, "switches") and event in self.machine.switches:
self.raise_config_error('Switch name "{name}" name used as event handler for {handler}. '
'Did you mean "{name}_active"?'.format(name=event, handler=handler), 1)
if not callable(handler):
raise ValueError('Cannot add handler "{}" for event "{}". Did you '
'accidentally add parenthesis to the end of the '
'handler you passed?'.format(handler, event))
raise AssertionError('Cannot add handler "{}" for event "{}". Did you '
'accidentally add parenthesis to the end of the '
'handler you passed?'.format(handler, event))

sig = inspect.signature(handler)
if 'kwargs' not in sig.parameters:
Expand Down

0 comments on commit 87b61e0

Please sign in to comment.