Comment by divbzero

Comment by divbzero 3 days ago

3 replies

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 3 days ago

Sadly many things define the __or__ operator, including dicts and sets which are common to find in pipelines. (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 2 days ago

    It’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.