Skip to content

Commit baa6bef

Browse files
joerendlemanaaltat
authored andcommitted
add a safety check to __getattr__ to avoid unwanted recursion
1 parent 90a62a0 commit baa6bef

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/robotlibcore/core/hybrid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def __get_members_from_instance(self, instance):
106106
yield name, getattr(owner, name)
107107

108108
def __getattr__(self, name):
109+
if name == "attributes":
110+
return super().__getattribute__(name)
109111
if name in self.attributes:
110112
return self.attributes[name]
111113
msg = "{!r} object has no attribute {!r}".format(type(self).__name__, name)

utest/test_robotlibcore.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,13 @@ def test_library_cannot_be_class():
104104
with pytest.raises(TypeError) as exc_info:
105105
HybridCore([HybridLibrary])
106106
assert str(exc_info.value) == "Libraries must be modules or instances, got class 'HybridLibrary' instead."
107+
108+
def test_get_library_attr():
109+
class TestClass(HybridCore):
110+
def __init__(self):
111+
self.a = self.b *2
112+
super().__init__()
113+
114+
with pytest.raises(AttributeError):
115+
TestClass()
116+

0 commit comments

Comments
 (0)