Skip to content

Commit edeb2c2

Browse files
authored
Merge pull request #307 from compas-dev/repr_fixes
Fixed reprs following compas release
2 parents fd5a3ce + c7679a7 commit edeb2c2

File tree

7 files changed

+11
-13
lines changed

7 files changed

+11
-13
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Unreleased
1414

1515
**Changed**
1616

17+
* Made consistent use of ``repr`` in nested objects
18+
1719
**Fixed**
1820

1921
* Fixed bug in ``compas.backends.PyBulletClient.convert_mesh_to_body`` circumventing PyBullet's propensity to cache

docs/examples/03_backends_ros/files/03_forward_kinematics_urdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
print("Frame in the world coordinate system")
1010
print(frame_WCF)
1111

12-
assert str(frame_WCF.point) == 'Point(0.300, 0.100, 0.500)'
12+
assert repr(frame_WCF.point) == 'Point(0.300, 0.100, 0.500)'

src/compas_fab/backends/ros/messages/direct_ur.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ def __init__(self, **kwargs):
1010
setattr(self, k, v)
1111

1212
def __str__(self):
13-
result = ""
14-
for key, value in self.__dict__.items():
15-
if value:
16-
result += "%s, " % value
17-
return result[:-2]
13+
return ", ".join(["{!r}" for value in self.__dict__.values() if value])
1814

1915
def __repr__(self):
2016
return self.__str__

src/compas_fab/robots/constraints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def transform(self, transformation):
155155

156156
def __repr__(self):
157157
"""Printable representation of :class:`BoundingVolume`."""
158-
return "BoundingVolume({0}, {1})".format(self.type, self.volume)
158+
return "BoundingVolume({!r}, {!r})".format(self.type, self.volume)
159159

160160
def copy(self):
161161
"""Make a copy of this :class:`BoundingVolume`.
@@ -307,7 +307,7 @@ def scale(self, scale_factor):
307307

308308
def __repr__(self):
309309
"""Printable representation of :class:`JointConstraint`."""
310-
return "JointConstraint('{0}', {1}, {2}, {3}, {4})".format(self.joint_name, self.value, self.tolerance_above, self.tolerance_below, self.weight)
310+
return "JointConstraint({!r}, {!r}, {!r}, {!r}, {!r})".format(self.joint_name, self.value, self.tolerance_above, self.tolerance_below, self.weight)
311311

312312
def copy(self):
313313
"""Create a copy of this :class:`JointConstraint`.
@@ -392,7 +392,7 @@ def transform(self, transformation):
392392

393393
def __repr__(self):
394394
"""Printable representation of :class:`OrientationConstraint`."""
395-
return "OrientationConstraint('{0}', {1}, {2}, {3})".format(self.link_name, self.quaternion, self.tolerances, self.weight)
395+
return "OrientationConstraint({!r}, {!r}, {!r}, {!r})".format(self.link_name, self.quaternion, self.tolerances, self.weight)
396396

397397
def copy(self):
398398
"""Create a copy of this :class:`OrientationConstraint`.
@@ -550,7 +550,7 @@ def transform(self, transformation):
550550

551551
def __repr__(self):
552552
"""Printable representation of :class:`PositionConstraint`."""
553-
return "PositionConstraint('{0}', {1}, {2})".format(self.link_name, self.bounding_volume, self.weight)
553+
return "PositionConstraint({!r}, {!r}, {!r})".format(self.link_name, self.bounding_volume, self.weight)
554554

555555
def copy(self):
556556
"""Create a copy of this :class:`PositionConstraint`.

src/compas_fab/robots/inertia.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def principal_moments(self):
5151
return [inertia_tensor[0][0], inertia_tensor[1][1], inertia_tensor[2][2]]
5252

5353
def __repr__(self):
54-
return "Inertia({0}, {1}, {2})".format(self.inertia_tensor, self.mass, self.center_of_mass)
54+
return "Inertia({!r}, {!r}, {!r})".format(self.inertia_tensor, self.mass, self.center_of_mass)
5555

5656
@staticmethod
5757
def calculate_inertia_tensor(cls, mesh):

src/compas_fab/robots/time_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, secs, nsecs):
2323
self.nsecs = int(nsecs)
2424

2525
def __str__(self):
26-
return 'Duration({}, {})'.format(self.secs, self.nsecs)
26+
return 'Duration({!r}, {!r})'.format(self.secs, self.nsecs)
2727

2828
def __repr__(self):
2929
return self.__str__()

src/compas_fab/robots/wrench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __getitem__(self, item):
186186
# ==========================================================================
187187

188188
def __repr__(self):
189-
return "Wrench({0}, {1})".format(self.force, self.torque)
189+
return "Wrench({!r}, {!r})".format(self.force, self.torque)
190190

191191
# ==========================================================================
192192
# helpers

0 commit comments

Comments
 (0)