My question is are the following two pieces of code run the same by the interpreter:
class A(object):
def __init__(self):
self.__x = None
@property
I've had to look it up, since I had this same question.
The functools package from the standard library will be getting a cached_property decorator as well. Unfortunately, it's only available from Python 3.8 (as of time of this post, it's 3.8a0). The alternative to waiting is to use a custom one, such as this one as mentioned by 0xc0de) or Django's, for now, then switch later:
from django.utils.functional import cached_property
# from functools import cached_property # Only 3.8+ :(