11from __future__ import annotations
22
3+ import logging
34import weakref
45from abc import ABC , ABCMeta
56from collections .abc import Callable , Mapping , MutableMapping , MutableSequence , MutableSet
67from enum import Flag
78from functools import partial
89from itertools import chain
9- from logging import getLogger
1010from typing import TYPE_CHECKING , Any , Self
1111
12- from jetpytools import Singleton , classproperty
12+ from jetpytools import Singleton , classproperty , to_arr
1313
1414from vsjetpack import is_from_vs_module
1515
1818__all__ = ["VSDebug" , "VSObject" , "VSObjectABC" , "VSObjectABCMeta" , "VSObjectMeta" ]
1919
2020
21- log = getLogger (__name__ )
21+ log = logging . getLogger (__name__ )
2222
2323
2424def _get_mangle_name (name : str ) -> str :
@@ -131,7 +131,7 @@ def vsdel_partial_register() -> None:
131131 )
132132
133133 setattr (obj , prefix + partial_attr , vsdel_partial_register )
134- core . register_on_destroy (vsdel_partial_register )
134+ register_on_destroy (vsdel_partial_register )
135135
136136 setattr (obj , prefix + register_attr , del_register )
137137 register_on_creation (del_register )
@@ -161,7 +161,14 @@ def __new__[MetaSelf: VSObjectMeta](
161161 mname = _get_mangle_name (name )
162162
163163 original_slots = tuple (namespace .get ("__slots__" , ()))
164- extra_slots = tuple (f"{ mname } { slot } " for slot in _objregisters )
164+ extra_slots = [f"{ mname } { slot } " for slot in _objregisters ]
165+
166+ # Collect all slots defined in parent classes to check if __weakref__ is already defined
167+ all_base_slots = set (chain .from_iterable (to_arr (getattr (base , "__slots__" , ())) for base in bases ))
168+
169+ if "__weakref__" not in original_slots and "__weakref__" not in all_base_slots :
170+ extra_slots .append ("__weakref__" )
171+
165172 namespace ["__slots__" ] = (* extra_slots , * original_slots )
166173
167174 for reg in _clsregisters :
@@ -246,17 +253,15 @@ def __init__(self, *, env_life: bool = True, core_fetch: bool = False, use_loggi
246253 trying to find the code path that is locking you into a EnvironmentPolicy.
247254 """
248255 if use_logging :
249- import logging
250-
251256 VSDebug ._print_func = logging .debug
252257 else :
253258 VSDebug ._print_func = print
254259
255260 if env_life :
256- register_on_creation (VSDebug ._print_env_live , True )
261+ register_on_creation (VSDebug ._print_env_live )
257262
258263 if core_fetch :
259- register_on_creation (VSDebug ._print_stack , True )
264+ register_on_creation (VSDebug ._print_stack )
260265
261266 @staticmethod
262267 def _print_stack (core_id : int ) -> None :
@@ -266,7 +271,7 @@ def _print_stack(core_id: int) -> None:
266271 def _print_env_live (core_id : int ) -> None :
267272 VSDebug ._print_func (f"New core created with id: { core_id } " )
268273
269- core . register_on_destroy (VSDebug ._print_core_destroy , False )
274+ register_on_destroy (partial ( VSDebug ._print_core_destroy , core . env . env_id , core_id ) )
270275 register_on_destroy (partial (VSDebug ._print_destroy , core .env .env_id , core_id ))
271276
272277 @staticmethod
0 commit comments