Skip to content

Commit

Permalink
Revert Link (drop _all_links). Added type annotations for link and dl…
Browse files Browse the repository at this point in the history
…ink.
  • Loading branch information
Alan Fleming committed May 11, 2024
1 parent a776397 commit 7741dbb
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions python/ipywidgets/ipywidgets/widgets/widget_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Propagate changes between widgets on the javascript side.
"""

from __future__ import annotations

from .widget import Widget, register, widget_serialization
from .widget_core import CoreWidget

Expand Down Expand Up @@ -51,25 +53,19 @@ class Link(CoreWidget):
source: a (Widget, 'trait_name') tuple for the source trait
target: a (Widget, 'trait_name') tuple that should be updated
"""
# maintain a set of links to keep them alive
_all_links = set()
_model_name = Unicode('LinkModel').tag(sync=True)
target = WidgetTraitTuple(help="The target (widget, 'trait_name') pair").tag(sync=True, **widget_serialization)
source = WidgetTraitTuple(help="The source (widget, 'trait_name') pair").tag(sync=True, **widget_serialization)
def __init__(self, source, target, **kwargs):

def __init__(self, source: tuple[Widget, str], target: tuple[Widget, str], **kwargs):
super().__init__(source=source, target=target, **kwargs)
self._all_links.add(self)

def close(self):
self._all_links.discard(self)
super().close()
# for compatibility with traitlet links
def unlink(self):
self.close()


def jslink(attr1, attr2):
def jslink(attr1: tuple[Widget, str], attr2: tuple[Widget, str]):
"""Link two widget attributes on the frontend so they remain in sync.
The link is created in the front-end and does not rely on a roundtrip
Expand Down Expand Up @@ -99,7 +95,7 @@ class DirectionalLink(Link):
_model_name = Unicode('DirectionalLinkModel').tag(sync=True)


def jsdlink(source, target):
def jsdlink(source: tuple[Widget, str], target: tuple[Widget, str]):
"""Link a source widget attribute with a target widget attribute.
The link is created in the front-end and does not rely on a roundtrip
Expand Down

0 comments on commit 7741dbb

Please sign in to comment.