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

Attempt to remove backcall. #14216

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 3 additions & 15 deletions IPython/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
This API is experimental in IPython 2.0, and may be revised in future versions.
"""

from backcall import callback_prototype


class EventManager(object):
"""Manage a collection of events and a sequence of callbacks for each.
Expand Down Expand Up @@ -63,23 +61,14 @@ def register(self, event, function):
"""
if not callable(function):
raise TypeError('Need a callable, got %r' % function)
callback_proto = available_events.get(event)
if function not in self.callbacks[event]:
self.callbacks[event].append(callback_proto.adapt(function))
self.callbacks[event].append(function)

def unregister(self, event, function):
"""Remove a callback from the given event."""
if function in self.callbacks[event]:
return self.callbacks[event].remove(function)

# Remove callback in case ``function`` was adapted by `backcall`.
for callback in self.callbacks[event]:
try:
if callback.__wrapped__ is function:
return self.callbacks[event].remove(callback)
except AttributeError:
pass

raise ValueError('Function {!r} is not registered as a {} callback'.format(function, event))

def trigger(self, event, *args, **kwargs):
Expand All @@ -100,9 +89,8 @@ def trigger(self, event, *args, **kwargs):
available_events = {}

def _define_event(callback_function):
callback_proto = callback_prototype(callback_function)
available_events[callback_function.__name__] = callback_proto
return callback_proto
available_events[callback_function.__name__] = callback_function
return callback_function

# ------------------------------------------------------------------------------
# Callback prototypes
Expand Down
13 changes: 0 additions & 13 deletions IPython/core/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,3 @@ def func3(*_):
self.em.trigger('ping_received')
self.assertEqual([True, True, False], invoked)
self.assertEqual([func3], self.em.callbacks['ping_received'])

def test_ignore_event_arguments_if_no_argument_required(self):
call_count = [0]
def event_with_no_argument():
call_count[0] += 1

self.em.register('event_with_argument', event_with_no_argument)
self.em.trigger('event_with_argument', 'the argument')
self.assertEqual(call_count[0], 1)

self.em.unregister('event_with_argument', event_with_no_argument)
self.em.trigger('ping_received')
self.assertEqual(call_count[0], 1)
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ python_requires = >=3.9
zip_safe = False
install_requires =
appnope; sys_platform == "darwin"
backcall
colorama; sys_platform == "win32"
decorator
exceptiongroup; python_version<'3.11'
Expand Down