How to Decompose path with attributes by scripting?

How can perform something similar to “Right Click > Expand Outline” by scripting ?
(To pass from pic1 to pic2)

l = Layer.copy()
l.flattenOutlines()
Layer.shapes = l.shapes.copy()
2 Likes