I'm talking about the so-called User Local View, which you can enter by selecting an object and pressing "Numpad /".
I can detect an active "User Perspective":
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
if area.spaces.active.local_view is not None:
print("I'm in a user perspective")
That local view causes some quirks with several Python operations. Is there a way to store the current local view, leave it and re-enter it upon finish?