Skip to content

Commit a667562

Browse files
committed
Make Cloned() handle None.
Currently, `Cloned(None)` will throw the exception that "`None` is not in the cloned environment". This is a bit annoying in cases where you to clone an optional object reference, such as a variable that is either a KinBody or `None`. This change adds logic to make `Cloned(None) = None`.
1 parent 23057b3 commit a667562

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/prpy/clone.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ def Cloned(*instances, **kwargs):
186186
clone_instances = list()
187187

188188
for instance in instances:
189+
# Check if an instance is `NoneType`.
190+
# If it is, it remains NoneType in the cloned environment.
191+
if instance is None:
192+
clone_instances.append(None)
193+
continue
194+
195+
# Clone each instance based on its type.
189196
if isinstance(instance, openravepy.Robot):
190197
clone_instance = clone_env.GetRobot(instance.GetName())
191198
elif isinstance(instance, openravepy.KinBody):

0 commit comments

Comments
 (0)