judy2k / stupid-python-tricks

Stupid Python tricks.
The Unlicense
144 stars 27 forks source link

improvements for gradually_worse_pi #18

Open danilovmy opened 2 years ago

danilovmy commented 2 years ago

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.