Skip to content

Commit aa6f457

Browse files
committed
Fixed #429.
1 parent fd63cc1 commit aa6f457

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Diff for: addons/source-python/packages/source-python/core/__init__.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# =============================================================================
9494
# >> CLASSES
9595
# =============================================================================
96-
class AutoUnload(object):
96+
class AutoUnload:
9797
"""Class used to auto unload specific instances.
9898
9999
Each inheriting class must implement an _unload_instance method.
@@ -144,12 +144,6 @@ def _add_instance(self, caller):
144144

145145
def _unload_instance(self):
146146
"""Base _unload_instance implementation."""
147-
raise NotImplementedError(
148-
'Class "{0}" from file "{1}" does not '.format(
149-
self.__class__.__name__, sys.modules[
150-
self.__class__.__module__].__file__.split(
151-
'plugins', 1)[1][1:]) +
152-
'have its own implementation of an _unload_instance method.')
153147

154148

155149
class WeakAutoUnload(AutoUnload):

Diff for: addons/source-python/packages/source-python/cvars/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# >> IMPORTS
77
# =============================================================================
88
# Source.Python Imports
9+
# Core
10+
from core import AutoUnload
911
# Cvars
1012
from _cvars import ConVar
1113
from _cvars import SP_CVAR_DLL_IDENTIFIER
@@ -28,3 +30,11 @@
2830
'SP_CVAR_DLL_IDENTIFIER',
2931
'cvar',
3032
)
33+
34+
35+
# =============================================================================
36+
# >> INITIALIZATION
37+
# =============================================================================
38+
# Inject AutoUnload into ConVar's inheritance tree so that custom instances
39+
# are kept alive until the plugin creating them remains loaded.
40+
ConVar.__bases__ = (AutoUnload,) + ConVar.__bases__

Diff for: addons/source-python/packages/source-python/cvars/public.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# =============================================================================
2323
# >> CLASSES
2424
# =============================================================================
25-
class PublicConVar(AutoUnload, ConVar):
25+
class PublicConVar(ConVar):
2626
"""Class used to set the notify flag on load/unload."""
2727

2828
def __init__(

0 commit comments

Comments
 (0)