On Wed, Jan 13, 2021 at 02:08:01AM -0800, Emily Bowman wrote: > Even if you define __bool__() as returning a bool, and error/undefined > behavior otherwise, that doesn't eliminate side effects. Is it even > possible to nail down a definition to the point that you can say, "Thou > shalt not mutate or cause anything" and have it meaningfully enforced in > the compiler or interpreter?
No, I don't think it is possible to enforce lack of side-effects. Not without rebuilding the language from the ground up with a clear, definitive and enforcable distinction between pure and impure functions. (I think Haskell does something like that. But trying to retrofit that into Python would probably be about as hard as building a restricted mode, and for similar reasons.) Besides, we probably don't want to prohibit side-effects in `__bool__`. That would prohibit useful tricks such as putting logging calls into a method you are trying to debug. -- Steve _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/L3M6RLVJ44VN4S34RYJTROSAZMUEPGWM/ Code of Conduct: http://python.org/psf/codeofconduct/