Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:52:46+00:00 2026-05-25T15:52:46+00:00

This causes an infinite recursive loop when setattr is called, when trying to set

  • 0

This causes an infinite recursive loop when setattr is called, when trying to set the value for some_prop, which is a property with a setter:

class TypeSystem(object):

    def __setattr__(self, key, value):
        if the_special_case is True:
            # do something
        else:
            super(TypeSystem,self).__setattr__(key,value)


class Entity(TypeSystem):

    @property
    def some_prop(self):
        some_prop = self.data.get('some_prop')
        if some_prop is None and hasattr(self,"some_prop"):
            some_prop = self.some_prop
        return some_prop

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

>>> entity = Entity()
>>> entity.some_prop = 3

This works fine for normal attributes that aren’t defined as properties because Super calls object’s setattr to prevent the recursive loop.

But because some_prop isn’t pre-defined, it looks like setattr is being invoked instead some_prop’s setter so it gets pulled into a loop.

I have tried this as well….

@some_prop.setter
def some_prop(self, value):
    super(TypeSystem, self).__setattr__("some_prop", value)

But it still goes into a recursive loop. I’m not seeing how to avoid it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:52:47+00:00Added an answer on May 25, 2026 at 3:52 pm

    This has nothing to do with __setattr__ or your TypeSystem. Your problem is

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

    That is clearly an infinite loop – you’re trying to set the property in the property’s setter.

    You have the same problem in the getter:

    some_prop = self.some_prop
    

    will cause an infinite loop as well — you’re trying to get the property in the property’s getter.

    You need to use another variable to hold the actual data:

    class Entity(TypeSystem):
    
        @property
        def some_prop(self):
            some_prop = self.data.get('some_prop')
            if some_prop is None and hasattr(self,"_some_prop"):
                some_prop = self._some_prop
            return some_prop
    
        @some_prop.setter
        def some_prop(self,value):
            self._some_prop = value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code below causes infinate loop problem (as documented). So how do I set
New to oop and was just wondering why this causes an infinite loop: while
This causes a compile-time exception: public sealed class ValidatesAttribute<T> : Attribute { } [Validates<string>]
I hava a thread in which I have an infinite loop, doing some network
When a ComboBox is clicked this causes it to be selected in the window.
I have no idea. This causes seemingly random time-outs. These in turn break the
It seems UITextFields convert all non-breaking spaces (nbsp, U+00A0) to spaces (U+0020). This causes
This declaration causes an overflow in VBA: Const OVERFLOWS As Long = 10 *
What causes this error, how can I fix it? Detailed Error Information Module IIS
The RIGHT JOIN on this query causes a TABLE ACCESS FULL on lims.operator .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.