Hello, On Wed, 13 Jan 2021 18:27:07 +1100 Chris Angelico <ros...@gmail.com> wrote:
[] > > Optimizations are an implementation detail, and implementation > > details should not change the language. > > The language can also be defined in an optimization-friendly way, > though. Consider how we got positional-only arguments in Python: first > they existed in C-implemented functions in CPython, even though they > couldn't exist in pure Python code, and then the functionality got > added to the language definition, thus permitting the optimization. In this case, the culprit seems to be that __bool__() and many other "special" methods may have side effects. So, just as "const" annotation would be useful for variables, "pure" (side-effect free) annotation would be useful for functions. But that alone won't help due to too-dynamic nature of Python. It's not much of an optimization if, at runtime, at each call-site, you need to check whether a function is pure to decide if you have to call it, or may skip it. Instead, that rather be done at compile time. But checking which method (pure or impure) will be called when is again complicated statically in Python. What to do about that? Well, we can introduce, ahem, some "strict" mode, in which *all* __bool__(), __gt__(), and friends must be declared pure, and for good measure, returning bool. Then we know we can skip any such method call. You see, all heresy starts from small things... [] -- 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/4P52JORZ4WBCPC6DERRITDRETEFWT73H/ Code of Conduct: http://python.org/psf/codeofconduct/