Skip to content

Commit

Permalink
Change binding to hold reference to source.
Browse files Browse the repository at this point in the history
This was a workaround when proper reference counting wasn't fully working.
  • Loading branch information
cmeyer committed Aug 15, 2024
1 parent 860979a commit f9ff65b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions nion/utils/Binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from __future__ import annotations

# standard libraries
import functools
import typing
import weakref

# third party libraries
# none
Expand Down Expand Up @@ -56,8 +54,7 @@ def __init__(self, source: typing.Optional[Observable.ObservableLike], *,
self.source_getter: typing.Optional[typing.Callable[[], typing.Any]] = None
self.source_setter: typing.Optional[typing.Callable[[typing.Any], None]] = None
self.target_setter: typing.Optional[typing.Callable[[typing.Any], None]] = None
# Python 3.9+: should weakref.ReferenceType
self.__source_ref: typing.Optional[typing.Any] = weakref.ref(source) if source else None
self.__source = source
self._closed = False

# not thread safe
Expand All @@ -69,7 +66,7 @@ def close(self) -> None:
@property
def source(self) -> typing.Optional[typing.Any]:
"""Return the source of the binding. Thread safe."""
return self.__source_ref() if self.__source_ref else None
return self.__source

@property
def converter(self) -> typing.Optional[Converter.ConverterLike[typing.Any, typing.Any]]:
Expand Down

0 comments on commit f9ff65b

Please sign in to comment.