0

I have a class that I'm trying to set is_duplicate to True like:

file = FileProperties(long, lat, timestamp, compas, filename)
[...]
file.is_duplicate = True

And I get a RuntimeError: maximum recursion depth exceeded while calling a Python object what exactly am I doing wrong? The file class creation is also happening in a for loop, but I don't think that's the issue with this specific error.

class FileProperties(object):
    def __init__(self, longitude, latitude, timestamp, compas, filename):
        self._longitude = longitude
        self._latitude = latitude
        self._timestamp = timestamp
        self._filename = filename
        self._compas = compas
        self._duplicate = False
        self._teleporting = False

    @property
    def get_lat(self):
        return self._latitude

    @property
    def get_long(self):
        return self._longitude

    @property
    def get_timestamp(self):
        return self._timestamp

    @property
    def get_filename(self):
        return self._filename

    @property
    def get_compas(self):
        return self._compas

    @property
    def is_duplicate(self):
        return self._duplicate

    @property
    def is_teleporting(self):
        return self._teleporting

    @is_duplicate.setter
    def is_duplicate(self, value):
        self.is_duplicate = value

    @is_teleporting.setter
    def is_teleporting(self, value):
        self._teleporting = value
2
  • 2
    You should question why you are using getters at all for these simple properties. Commented Jul 14, 2016 at 15:47
  • because I will be doing validation on them, but I wanted to simplify the script for help Commented Jul 14, 2016 at 17:55

1 Answer 1

3

In:

@is_duplicate.setter
def is_duplicate(self, value):
    self.is_duplicate = value

Change self.is_duplicate to self._duplicate and it should work.

The reason for this bug is that you are assigning the method is_duplicate instead of the attribute _duplicate hence you are creating an infinite call loop, because the method is trying to set itself in an infinite loop because it goes through the setter again and again and again...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.