daft-dev / daft

Render probabilistic graphical models using matplotlib
https://docs.daft-pgm.org
MIT License
675 stars 120 forks source link

Assert statements in the Code #167

Closed nstarman closed 11 months ago

nstarman commented 11 months ago

There's a few assert statements in the code, of which this is one:

https://github.com/daft-dev/daft/blob/33def2d6fd130d0e3376aa4902fee535d49a9e92/daft.py#L587-L589

Asserts are stripped in optimize mode (https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement), which can change the behaviour of a package.

nstarman commented 11 months ago

I think a simple switch to if not X: raise AssertionError() isn't removed by -O. Want to make the switch?

dfm commented 11 months ago

I don't think we were using asserts there for any sensible reasons! I'd probably prefer to use this as an opportunity to raise more appropriate exception types :D