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

DM-31507 Modify data-structures to aid ref counting #568

Merged
merged 1 commit into from
Aug 26, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

from . import ConfigurableAction

import weakref


class ConfigurableActionStructUpdater:
"""This descriptor exists to abstract the logic of using a dictionary to
Expand Down Expand Up @@ -126,7 +128,7 @@ class ConfigurableActionStruct:

def __init__(self, config: Config, field: ConfigurableActionStructField,
value: Mapping[str, ConfigurableAction], at: Any, label: str):
object.__setattr__(self, '_config', config)
object.__setattr__(self, '_config_', weakref.ref(config))
object.__setattr__(self, '_attrs', {})
object.__setattr__(self, '_field', field)
object.__setattr__(self, '_history', [])
Expand All @@ -137,6 +139,13 @@ def __init__(self, config: Config, field: ConfigurableActionStructField,
for k, v in value.items():
setattr(self, k, v)

@property
def _config(self) -> Config:
# Config Fields should never outlive their config class instance
# assert that as such here
assert(self._config_() is not None)
return self._config_()

@property
def history(self) -> List[tuple]:
return self._history
Expand Down