Skip to content

Commit

Permalink
Field name checks for StructTuple
Browse files Browse the repository at this point in the history
This PR introduces a new check for field names in a StructTuple, preventing any that over-ride existing members of the tuple base class.  It is intended to trap a gotcha in JointDistributionCoroutine if a user names a variable "index" or "count".
  • Loading branch information
chrism0dwk authored Jul 30, 2024
1 parent a6f3989 commit 53ed3c2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tensorflow_probability/python/internal/structural_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def _validate_field_names(field_names):
if name.startswith('_'):
raise ValueError(
'Field names cannot start with an underscore: {}'.format(name))
if name in dir(tuple):
raise ValueError(
'Field name {} is already a member of StructTuple'.format(name))
if name in seen:
raise ValueError('Encountered duplicate field name: {}'.format(name))
seen.add(name)
Expand Down

0 comments on commit 53ed3c2

Please sign in to comment.