stupid-python-tricks icon indicating copy to clipboard operation
stupid-python-tricks copied to clipboard

improvements for gradually_worse_pi

Open danilovmy opened this issue 2 years ago • 0 comments

Hello, Mark. We have a small conversation on PyCon DE 2022 after your talk. I have a small improvements for your "gradually_worse_pi"


class my_prop(math.__class__):
    _pi = math.pi`

    @property
    def pi(self):
        self._pi += 0.0001
        return self._pi

math.__class__ = my_prop

Here we have an inheritance from math module class, that's why we don't need override getattr and also we don't need change the sys import list. Probably those code can be more elegant and Pythonic.

danilovmy avatar Apr 18 '22 19:04 danilovmy