Skip to content

Commit

Permalink
Fixing __getattr__ methods to prevent maximum recursion depth when pi…
Browse files Browse the repository at this point in the history
…ckled
  • Loading branch information
LouisDesdoigts committed Nov 10, 2022
1 parent cf15a0b commit 1e9d242
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions dLux/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,13 @@ def __getattr__(self : Instrument, key : str) -> object:
item : object
The item corresponding to the supplied key in the sub-dictionaries.
"""

if self.optics is not None and hasattr(self.optics, 'layers') and \
if 'optics' in vars(self) and hasattr(self.optics, 'layers') and \
key in self.optics.layers.keys():
return self.optics.layers[key]
elif self.detector is not None and hasattr(self.detector, 'layers') and\
elif 'detector' in vars(self) and hasattr(self.detector, 'layers') and \
key in self.detector.layers.keys():
return self.detector.layers[key]
elif self.scene is not None and hasattr(self.scene, 'sources') and \
elif 'scene' in vars(self) and hasattr(self.scene, 'sources') and \
key in self.scene.sources.keys():
return self.scene.sources[key]
else:
Expand Down Expand Up @@ -550,7 +549,7 @@ def __getattr__(self : Optics, key : str) -> object:
item : object
The item corresponding to the supplied key in the layers dictionary.
"""
if key in self.layers.keys():
if 'layers' in vars(self) and key in self.layers.keys():
return self.layers[key]
else:
raise AttributeError("'{}' object has no attribute '{}'"\
Expand Down Expand Up @@ -814,7 +813,7 @@ def __getattr__(self : Scene, key : str) -> object:
The item corresponding to the supplied key in the sources
dictionary.
"""
if key in self.sources.keys():
if 'sources' in vars(self) and key in self.sources.keys():
return self.sources[key]
else:
raise AttributeError("'{}' object has no attribute '{}'"\
Expand Down Expand Up @@ -932,7 +931,7 @@ def __getattr__(self : Detector, key : str) -> object:
item : object
The item corresponding to the supplied key in the layers dictionary.
"""
if key in self.layers.keys():
if 'layers' in vars(self) and key in self.layers.keys():
return self.layers[key]
else:
raise AttributeError("'{}' object has no attribute '{}'"\
Expand Down

0 comments on commit 1e9d242

Please sign in to comment.