Sometimes I find myself in need of this nice operator that I used back in
the days when I was programming in .NET, essentially an expression

>>> expr ?? instead

should return expr when it `is not None` and `instead` otherwise.

A piece of code that I just wrote, you can see a use case:

    def _sizeof(self, context):
        if self.totalsizeof is not None:
            return self.totalsizeof
        else:
            raise SizeofError("cannot calculate size")

With the oprator it would just be

    def _sizeof(self, context):
        return self.totalsizeof ?? raise SizeofError("cannot calculate
size")



pozdrawiam,
Arkadiusz Bulski
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to