2323)
2424from .structures import DDSException , CanonicalPath , LocalDepPath , DDSErrorCode
2525from .structures_utils import LocalDepPathUtils , CanonicalPathUtils
26+ from ._config import get_option , accept_list_option , accept_dict_option
2627
2728_logger = logging .getLogger (__name__ )
2829
@@ -55,6 +56,11 @@ def _is_authorized_type(tpe: Type[Any], gctx: EvalMainContext) -> bool:
5556 return True
5657 if tpe in (int , float , str , bytes , PurePosixPath , FunctionType , ModuleType ):
5758 return True
59+ # Some specific structural types are more complex and can be user-controlled.
60+ if get_option (accept_list_option ) and tpe in (list ,):
61+ return True
62+ if get_option (accept_dict_option ) and tpe in (dict ,):
63+ return True
5864 if issubclass (tpe , object ):
5965 mod = inspect .getmodule (tpe )
6066 if mod is None :
@@ -90,9 +96,11 @@ def retrieve_object(
9096 obj_key = (local_path , mod_path )
9197
9298 if obj_key in gctx .cached_objects :
93- # _logger.debug(f"retrieve_object: found in cache: obj_key: {obj_key}")
99+ if debug :
100+ _logger .debug (f"retrieve_object: found in cache: obj_key: { obj_key } " )
94101 return gctx .cached_objects [obj_key ]
95- # _logger.debug(f"retrieve_object: not found in cache: obj_key: {obj_key}")
102+ if debug :
103+ _logger .debug (f"retrieve_object: not found in cache: obj_key: { obj_key } " )
96104
97105 fname = local_path .parts [0 ]
98106 sub_path = LocalDepPathUtils .tail (local_path )
@@ -112,21 +120,19 @@ def retrieve_object(
112120 # Looking into the globals (only if the scope is currently __main__ or __global__)
113121 mod_path = _mod_path (context_mod )
114122 if CanonicalPathUtils .head (mod_path ) not in ("__main__" , "__global__" ):
115- # _logger.debug(
116- # f"Could not load name %s and not in global context (%s), skipping ",
117- # fname,
118- # mod_path,
119- # )
123+ if debug :
124+ _logger .debug (
125+ f"Could not load name %s and not in global context (%s), skipping " ,
126+ fname ,
127+ mod_path ,
128+ )
120129 return None
121130 else :
122- # _logger.debug(
123- # f"Could not load name %s, looking into the globals (mod_path: %s, %s)",
124- # fname,
125- # mod_path,
126- # mod_path.get(0),
127- # )
128131 pass
129- # _logger.debug(f"Could not load name {fname}, looking into the globals")
132+ if debug :
133+ _logger .debug (
134+ f"Could not load name { fname } , looking into the globals"
135+ )
130136 if fname in gctx .start_globals :
131137 # _logger.debug(f"Found {fname} in start_globals")
132138 obj = gctx .start_globals [fname ]
@@ -151,10 +157,11 @@ def retrieve_object(
151157 ["__global__" ] + [str (x ) for x in local_path .parts ]
152158 )
153159 if not gctx .is_authorized_path (obj_path ):
154- # _logger.debug(
155- # f"Object[start_globals] {fname} of type {type(obj)} is not authorized (path),"
156- # f" dropping path {obj_path}"
157- # )
160+ if debug :
161+ _logger .debug (
162+ f"Object[start_globals] { fname } of type { type (obj )} is not authorized (path),"
163+ f" dropping path { obj_path } "
164+ )
158165 res = ExternalObject (obj_path )
159166 gctx .cached_objects [obj_key ] = res
160167 return res
@@ -171,21 +178,24 @@ def retrieve_object(
171178 str ,
172179 ),
173180 ):
174- # _logger.debug(
175- # f"Object[start_globals] {fname} ({type(obj)}) of path {obj_path} is authorized,"
176- # )
181+ if debug :
182+ _logger .debug (
183+ f"Object[start_globals] { fname } ({ type (obj )} ) of path { obj_path } is authorized,"
184+ )
177185 res = AuthorizedObject (obj , obj_path )
178186 gctx .cached_objects [obj_key ] = res
179187 return res
180188 else :
181- # _logger.debug(
182- # f"Object[start_globals] {fname} of type {type(obj)} is noft authorized (type), dropping path {obj_path}"
183- # )
189+ if debug :
190+ _logger .debug (
191+ f"Object[start_globals] { fname } of type { type (obj )} is noft authorized (type), dropping path { obj_path } "
192+ )
184193 res = ExternalObject (obj_path )
185194 gctx .cached_objects [obj_key ] = res
186195 return res
187196 else :
188- # _logger.debug(f"{fname} not found in start_globals")
197+ if debug :
198+ _logger .debug (f"{ fname } not found in start_globals" )
189199 gctx .cached_objects [obj_key ] = None
190200 return None
191201 res = cls ._retrieve_object_rec (sub_path , loaded_mod , gctx )
0 commit comments