Skip to content

Infinite Recursion in repr with bi-directional relationships #95

@dcbaker

Description

@dcbaker

Take a fairly trivial example (which has obviously been simplified to the point of absurdity):

import attr

@attr.s
class Test():
    attr = attr.ib(default=None)

test = Test()
other = Test()
test.attr = other
other.attr = test

print(repr(test))

This will result in infinite recursion. This can be worked around by setting repr=False in the attr.s decorator.

I've sat on this bug for a week trying to come up with a good solution, and I can't think of anything good. I'm starting to think the best solution is to add a warning to the documentation of this behavior and calling it good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions