Skip to content

Commit

Permalink
Merge pull request #1828 from chrism0dwk:chrism0dwk-patch-1
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 661311249
  • Loading branch information
tensorflower-gardener committed Aug 9, 2024
2 parents be996d8 + 53ed3c2 commit 95767a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tensorflow_probability/python/internal/structural_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def __getnewargs__(self):
"""Return self as a plain tuple. Used by copy and pickle."""
return tuple(self)

def __getattr__(self, attr):
def __getattribute__(self, attr):
if attr.startswith('_'):
return super().__getattribute__(attr)
attr_idx = self._field_name_to_index.get(attr)
if attr_idx is None:
raise AttributeError('StructTuple has no attribute {}'.format(attr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def foo(a, b):

self.assertEqual(3, nest_util.call_fn(foo, t(1, 2)))

def testTupleMethods(self):
t = structural_tuple.structtuple(['count', 'a', 'b'])
self.assertEqual(t(1, 2, 3).count, 1)

def testMoreThan255Fields(self):
num_fields = 1000
t = structural_tuple.structtuple(
Expand Down

0 comments on commit 95767a1

Please sign in to comment.