Skip to content

Commit

Permalink
fix: do not recurse into sys in ModuleHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Armstrong committed Jul 23, 2024
1 parent b48da63 commit ac001f7
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions ivy/stateful/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ def _find_variables(
return vs
elif not hasattr(obj, "__dict__"):
return vs
for k, v in obj.__dict__.items():
if v is not None and k[0:2] != "__" and k != "_module_dict":
ret = self._find_variables(
obj=v,
without_initialisation=without_initialisation,
_visited=_visited,
)
if ret:
vs[k[1:] if k[0] == "_" else k] = ret
try:
obj_name = obj.__name__ if hasattr(obj, "__name__") else None
except:
obj_name = None
if obj_name not in ["sys"]: # do not recurse into any objects in this list
for k, v in obj.__dict__.items():
if v is not None and k[0:2] != "__" and k != "_module_dict":
ret = self._find_variables(
obj=v,
without_initialisation=without_initialisation,
_visited=_visited,
)
if ret:
vs[k[1:] if k[0] == "_" else k] = ret
return vs

def _find_buffers(self):
Expand Down Expand Up @@ -229,14 +234,19 @@ def _wrap_call_methods(
return
if not hasattr(obj, "__dict__"):
return
for k, val in obj.__dict__.items():
if k[0:2] == "__":
continue
k = f"{key}/{k}" if key != "" else k
if val is not None:
self._wrap_call_methods(
keychain_mappings, key=k, obj=val, _visited=_visited
)
try:
obj_name = obj.__name__ if hasattr(obj, "__name__") else None
except:
obj_name = None
if obj_name not in ["sys"]: # do not recurse into any objects in this list
for k, val in obj.__dict__.items():
if k[0:2] == "__":
continue
k = f"{key}/{k}" if key != "" else k
if val is not None:
self._wrap_call_methods(
keychain_mappings, key=k, obj=val, _visited=_visited
)
return

def _call(self, *args, v=None, buffers=None, **kwargs):
Expand Down

0 comments on commit ac001f7

Please sign in to comment.