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

Fix splinepy #327 #185

Merged
merged 3 commits into from
Feb 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gustaf/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GustafBase:
methods are defined as classmethods..
"""

__slots__ = ()
__slots__ = ("__weakref__",)

def __init_subclass__(cls, *args, **kwargs):
"""
Expand Down
3 changes: 2 additions & 1 deletion gustaf/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from gustaf.helpers import data, options, raise_if
from gustaf.helpers import _base, data, options, raise_if

__all__ = [
"data",
"options",
"raise_if",
"_base",
]
29 changes: 29 additions & 0 deletions gustaf/helpers/_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""gustaf/gustaf/helpers/_base.py

Base class for helper
"""

from weakref import ref

from gustaf._base import GustafBase


class HelperBase(GustafBase):
"""
Minimal base layer for helper classes to avoid cyclic referencing.
Instead of saving a pure reference to helpee object, this will create a
weakref instead. This class defines `_helpee` setters and getters, so that
existing code can remain untouched.
"""

__slots__ = ("_helpee_weak_ref",)

@property
def _helpee(self):
"""Returns dereferenced weak ref. Setter will create and save weakref
of a helpee."""
return self._helpee_weak_ref()

@_helpee.setter
def _helpee(self, helpee):
self._helpee_weak_ref = ref(helpee)
9 changes: 3 additions & 6 deletions gustaf/helpers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np

from gustaf._base import GustafBase
from gustaf.helpers._base import HelperBase


class TrackedArray(np.ndarray):
Expand Down Expand Up @@ -195,11 +195,8 @@ def make_tracked_array(array, dtype=None, copy=True):
return tracked


class DataHolder(GustafBase):
__slots__ = (
"_helpee",
"_saved",
)
class DataHolder(HelperBase):
__slots__ = ("_saved",)

def __init__(self, helpee):
"""Base class for any data holder. Behaves similar to dict.
Expand Down
5 changes: 3 additions & 2 deletions gustaf/helpers/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from copy import deepcopy

from gustaf.helpers._base import HelperBase
from gustaf.helpers.raise_if import ModuleImportRaiser


Expand Down Expand Up @@ -224,7 +225,7 @@ def make_valid_options(*options):
return valid_options


class ShowOption:
class ShowOption(HelperBase):
"""
Behaves similar to dict, but will only accept a set of options that's
applicable to the helpee class. Intended use is to create a
Expand All @@ -234,7 +235,7 @@ class ShowOption:
specific common routines. ShowOption and ShowManager in a sense.
"""

__slots__ = ("_helpee", "_options")
__slots__ = ("_options",)

_valid_options = {}

Expand Down
Loading