Skip to content

Commit

Permalink
perf: only add notifiers when they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Sep 14, 2022
1 parent 7ad779a commit aa23cc0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions traitlets/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,14 +1414,16 @@ def _notify_observers(self, event):
name, type = event.name, event.type

callables = []
callables.extend(self._trait_notifiers.get(name, {}).get(type, []))
callables.extend(self._trait_notifiers.get(name, {}).get(All, []))
callables.extend(
self._trait_notifiers.get(All, {}).get(type, []) # type:ignore[call-overload]
)
callables.extend(
self._trait_notifiers.get(All, {}).get(All, []) # type:ignore[call-overload]
)
if name in self._trait_notifiers:
callables.extend(self._trait_notifiers.get(name, {}).get(type, []))
callables.extend(self._trait_notifiers.get(name, {}).get(All, []))
if All in self._trait_notifiers:
callables.extend(
self._trait_notifiers.get(All, {}).get(type, []) # type:ignore[call-overload]
)
callables.extend(
self._trait_notifiers.get(All, {}).get(All, []) # type:ignore[call-overload]
)

# Now static ones
magic_name = "_%s_changed" % name
Expand Down

0 comments on commit aa23cc0

Please sign in to comment.