定型コードなしで単純なクラスを定義するためにattrsを使用しています。デコレーター__repr__
は、すべての属性の値を示す を自動的に生成します。デフォルト値を持たない属性のみを表示したい:
>>> import attr
>>> @attr.s
... class Coordinates(object):
... x = attr.ib(default=0)
... y = attr.ib(default=0)
>>> Coordinates() # wanted output: Coordinates()
Coordinates(x=0, y=0)
>>> Coordinates(x=0, y=0) # wanted output: Coordinates()
Coordinates(x=0, y=0)
>>> Coordinates(x=1) # wanted output: Coordinates(x=1)
Coordinates(x=1, y=0)
>>> Coordinates(x=1, y=1) # output OK
Coordinates(x=1, y=1)
これを達成する合理的に簡単な方法はありますか?