3 ms·
I suppose you could use the same trick with __ror__ and | (as long as the left-hand side doesn’t define __or__). x = Model.objects.all() | by_pk | call(dict.
by divbzero 1y ago
I suppose you could use the same trick with __ror__ and | (as long as the left-hand side doesn’t define __or__).
x = Model.objects.all() | by_pk | call(dict.values) | to_list | get('name') | _map(str.title) | log_debug | to_json
- btown 1y agoSadly many things define the __or__ operator, including dicts and sets which are common to find in pipelines. (https://peps.python.org/pep-0584/ https://peps.python.org/pep-0584/ was a happy day for everyone but me!) In practice, rshift gives a lot more flexibility! And you’d rarely chain after a numeric value.
- mananaysiempre 1y agoIt’s still useful in related situations. The following crime often finds its way into my $PYTHONSTARTUP: class more: def __ror__(self, other): import pydoc pydoc.pager(str(other)) more = more() and here the low precedence of | is useful.
- ck45 1y agoOr overloading division like https://scapy.net/ https://scapy.net/