Skip to content

Provide event handlers with all the arguments they request #1360

@drzraf

Description

@drzraf

Is your feature request related to a problem? Please describe.

Arguments set passed to handlers is very opinionated and overly restricted.
I can't access namespace, sid, event's name whenever I want.
It'd be easy to pass keyword arguments and let handlers do whatever they want with them.

def log(self, event, data):
  # Do something with {event} & {data}

# Made a loop to avoid cumbersome repetitions due to wrapping
# my handler... for the sole purpose of providing `evt`
# but it doesn't make the code clearer
for evt in ['foo', 'bar']:
    sio.on(evt, handler=lambda data: log(evt, data))
    

Describe the solution you'd like

def log(self, event, data, sid, namespace):
  # Do something with {*}
  # or maybe **kwarg and let me choose for it
  # or any solution that allows me to access *all* properties of this message

sio.on('foo', namespace='/', handler=log)
sio.on('bar', handler=log)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions