Hello, On Thu, 14 Jan 2021 12:45:11 +1300 Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> On 14/01/21 6:17 am, Paul Sokolovsky wrote: > > For > > example, print() would be considered "pure", as its purpose is to > > provide program output, not arbitrarily change program state > > That definition of purity wouldn't really help with optimisations, > though, because optimising away a print() call would still cause > a visible change in the program's behaviour. But nobody talked about optimizing away generic "pure"-annotated functions (which would differ from "mathematical" definition of purity), only about optimizing "pure" *dunder* methods (which are by definition special methods, which are called implicitly; or not called, which is the aim we discuss). "Pure" annotation on other functions are drawn only to verify that a dunder itself is indeed "pure". And "pure" is of course a pretty rough term meaning "not causing *non-local* side effects". print() in that regard causes only localized side effect of output appearing on terminal. print() also can be redefined to output to io.StringIO, and it still will be "pure", as side effects will be localized to just that io.StringIO object (which has dedicated purpose to be print's buffer in the first place). But if user redefines print() to e.g. manipulate sys.path, it's now causes non-local side effects, and thus breaks API contract re: "purity". > -- > Greg [] -- 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/B6E2NZYIURXDRZ336TBAVCANI666KH4A/ Code of Conduct: http://python.org/psf/codeofconduct/