Non-aware operators PEP505

Hi all, Just want to follow up on discussions from before by saying that I came to a conclusion that from my POV non-aware operators would be an excellent addition to python. The number of times that I need to write: pal = None if self.pal is None else self.pal.rgb_to_cmy() or alternatively: pal = None if self.pal is None: pal = self.pal.rgb_to_cmy() is still fairly high. The first one is one-line, but its readability is, although not the worst, but is not satisfactory in the context of other practices I have employed. The second one has good readability, but it takes 3 lines for operation, which I think shouldn’t take more than 1 line. —— Now following up on my thoughts on deferred evaluation this case could be solved by its side effect, which is allowing user to control evaluation order. However, I think it would be more suitable for corner cases and more complex tool building due to its verbosity and readability, which I think would be better than many corner-case hacks, but nowhere as elegant as say non-aware operator syntax. So I think regardless of whether deferred evaluation is ever implemented, this PEP( https://peps.python.org/pep-0505/ <https://peps.python.org/pep-0505/>) could be a very useful addition given the frequency of such cases. —— Even a minimal implementation of it for would be very useful, say simple binary operator with __has_value__ object protocol. —— Maybe someone knows a better way to write the example above? Regards, DG
participants (1)
-
Dom Grigonis