y0-causal-inference / y0

❓y0 (pronounced "why not?") is for causal inference in Python
https://y0.readthedocs.io
BSD 3-Clause "New" or "Revised" License
44 stars 9 forks source link

Unexplained behavior when instantiating a Population Probability #211

Closed rjc955 closed 7 months ago

rjc955 commented 7 months ago

The next two commented-out lines produce a mypy error:

pi1 = Population("pi1")
test_1_district_probability = PP[pi1](Z | X1)

Here's the error:

error: Type application targets a non-generic function or class  [misc]

test_transport.py uses a similar syntax and does not trigger the error, so I'm probably missing something simple.

The next line does not trigger an error:

test_1_district_probability = PP[Population("pi1")](Z | X1)
djinnome commented 7 months ago

To be clear, this does not trigger an error in the python interpreter, only in mypy, which may suggest a bug in mypy?

djinnome commented 7 months ago

Now the problem is no longer being reported by mypy, so maybe the problem has been fixed?

rjc955 commented 7 months ago

The issue reappeared and I found the source of the problem. Explicitly assigning a type to the alias PP when instantiating it at the end of dsl.py gets rid of the MyPy errors. It's fixed in this commit, currently just in the counterfactual_transportability branch.