hdl.ast: improve interaction of ValueCastable with custom __getattr__.
Avoid calling `__getattr__("_ValueCastable__lowered_to")` when
a ValueCastable has custom `__getattr__` implementation; this avoids
the need for downstream code to be aware of this implementataion
detail.
This commit is contained in:
parent
fac1b4b2d1
commit
11914a1e67
2 changed files with 24 additions and 6 deletions
|
|
@ -1060,6 +1060,18 @@ class MockValueCastableNoOverride(ValueCastable):
|
|||
pass
|
||||
|
||||
|
||||
class MockValueCastableCustomGetattr(ValueCastable):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@ValueCastable.lowermethod
|
||||
def as_value(self):
|
||||
return Const(0)
|
||||
|
||||
def __getattr__(self, attr):
|
||||
assert False
|
||||
|
||||
|
||||
class ValueCastableTestCase(FHDLTestCase):
|
||||
def test_not_decorated(self):
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
|
|
@ -1083,6 +1095,10 @@ class ValueCastableTestCase(FHDLTestCase):
|
|||
sig3 = Value.cast(vc)
|
||||
self.assertIs(sig1, sig3)
|
||||
|
||||
def test_custom_getattr(self):
|
||||
vc = MockValueCastableCustomGetattr()
|
||||
vc.as_value() # shouldn't call __getattr__
|
||||
|
||||
|
||||
class SampleTestCase(FHDLTestCase):
|
||||
def test_const(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue