Skip to content

Commit fcdad6e

Browse files
committed
Changed GetTrajectoryTags() to EAFP-style.
Instead of using an if-check, GetTrajectoryTags() now just tries JSON deserialization and catches a ValueError. This is more robust as it also catches situations where the deserialization fails due to the trajectory description being invalid or whitespace, but not None.
1 parent b2d2ca2 commit fcdad6e

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/prpy/util.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@ def GetTrajectoryTags(traj):
229229
"""
230230
import json
231231

232-
description = traj.GetDescription()
233-
234-
if description:
235-
return json.loads(description)
236-
else:
232+
try:
233+
return json.loads(traj.GetDescription())
234+
except ValueError:
237235
return dict()
238236

239237

0 commit comments

Comments
 (0)