Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function that returns an array listing the events #96

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyee/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def _add_event_handler(self, event, k, v):
def _emit_run(self, f, args, kwargs):
f(*args, **kwargs)

def event_names(self):
# Returns an array listing the events
return list(self._events.keys())[1:]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This slice is dropping the first key:

❯ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> xs = [1, 2, 3]
>>> xs[1:]
[2, 3]
>>> 

I don't think this is what we want. I think you were trying to clone the list:

>>> xs = [1, 2, 3]
>>> xs[:]
[1, 2, 3]

The motivation for doing this is so that self._events may mutate before you've completed iterating over its keys - the list gets that out of the way for us. Good thinking! But I think that's already handled by converting it to a list:

>>> xs is xs
True
>>> xs is xs[:]
False
>>> xs is list(xs)
False

In other words, try the following:

def event_names(self):
    return list(self._events.keys())

Copy link
Contributor Author

@leirons leirons Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to drop the first key because in the first place always new_listener, and it's not a really listener, or am i wrong?

ok, l will do it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior in node.js? do they filter out internal events there? I think the easiest thing will be to copy that interface.


def _emit_handle_potential_error(self, event, error):
if event == 'error':
if error:
Expand Down