-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsafe variable naming in JointDistributionCoroutine
#1827
Comments
JointDistributionCoroutine
variable naming issueJointDistributionCoroutine
Thanks, Chris -- looks like the I think we should just add those two to this check on validating names. If someone wants a variable named What do you think? |
@ColCarroll sounds a pragmatic way forward. I've suggested a solution in #1828. See what you think... |
The goal of structtuple was to mimic namedtuple's behavior, which neither forbids these names, nor balks at using them. It sounds like we didn't quite mimic its behavior correctly. |
I'm guessing we need to use |
The
JointDistributionCoroutine
class is a fantastic way of constructing a joint probability distribution, particularly with random variables that depend on each other. The class allows you to name your variable, and outputs a joint sample as aStructTuple
(which AFAICS is just anamedtuple
under the hood).However, you have to be careful how you name your variables. Consider the trivial example with a variable inadvertently named
count
:For this model, calling
model.sample()
apparently returns aStructTuple
with acount
field as expected:Great! But what happens if I try to access
count
?Oh dear. It looks like we get the bound
tuple.count
method back instead. For the same reason, this wrecks anytfd.JointDistributionCoroutine
methods that depends on accessingStructTuple
attributes. e.g.A fix might just be to document the reserved names in the Name resolution paragraph in the doc for this class. But I wonder if there's something deeper we could do?
Chris
The text was updated successfully, but these errors were encountered: