ifitzsimmons / DynamoDbDataMarshalling

A class that handles DynamoDB Data marshalling with recursion
0 stars 0 forks source link

repr should be an a text representation of the class #1

Open jack-homan-deloitte opened 3 years ago

jack-homan-deloitte commented 3 years ago

https://github.com/ifitzsimmons/DynamoDbDataMarshalling/blob/1cc2b44fa4a065fce9ebaf9f2548bb7f5eb89b7e/MarshalDynamoDbItem.py#L93

# repr should mean this

class BinaryOp:

    def __init__(self, x, y):
        self._x = x
        self._y = y

    def __repr__(self):
        return f"BinaryOp({self._x}, {self._y})"

    def add(self):
        return self._x + self._y

assert eval(repr(BinaryOp(1, 2)) == BinaryOp(1, 2)
ifitzsimmons commented 3 years ago

@jack-homan-deloitte My __repr__ is returning a string, no? It's just the object.

jack-homan-deloitte commented 3 years ago

right but when you use repr(obj) it should return a string representation of the object that can copy and paste back to the repl to recreate it e.g.

>>> repr(BinaryOp(1, 2))
BinaryOp(1, 2)