This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ronaldoussoren
Recipients denis-osipov, docs@python, levkivskyi, ronaldoussoren, xtreak
Date 2018-10-31.15:59:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541001547.24.0.788709270274.issue35119@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not convinced that any change is needed, this is completely expected behaviour (and not special to modules).

The following code also raises RecursionError:

class VerboseObject:
    def __setattr__(self, nm, value):
        print(f"Setting {nm} to {value}")
        setattr(self, nm, value)

o = VerboseObject()
o.a = 42

This is because setattr() calls the __setattr__ method, which calls setattr() again, ... .


The fix is to call super().__setattr__ instead:

class VerboseObject:
    def __setattr__(self, nm, value):
        print(f"Setting {nm} to {value}")
        super().__setattr__(nm, value)

o = VerboseObject()
o.a = 42
History
Date User Action Args
2018-10-31 15:59:07ronaldoussorensetrecipients: + ronaldoussoren, docs@python, levkivskyi, denis-osipov, xtreak
2018-10-31 15:59:07ronaldoussorensetmessageid: <1541001547.24.0.788709270274.issue35119@psf.upfronthosting.co.za>
2018-10-31 15:59:07ronaldoussorenlinkissue35119 messages
2018-10-31 15:59:07ronaldoussorencreate