Hello, On Thu, 14 Jan 2021 03:29:35 +1100 Steven D'Aprano <st...@pearwood.info> wrote:
> 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. Surely, if we do that, we wouldn't use Haskell's definition of purity ;-). Rather, a practical definition of purity, Python-style. For example, print() would be considered "pure", as its purpose is to provide program output, not arbitrarily change program state (so, all of __str__, __repr__, __format__ would need to be pure, but if someone overrode print() to shoot at random modules/data at them, then they shoot themselves in the feet, nothing else). [] -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ 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/44IGY7CWR3OPM2RN64GJHXOML4ZMW3IX/ Code of Conduct: http://python.org/psf/codeofconduct/