There is actually a solution to this problem that does not require a script. It requires multiple processing steps, but you could chain these tools together in a graphical model.
I'm using QGIS, but I believe this could be done in ArcMap in a similar fashion (though perhaps using different tools).
Say you have three features in a single layer that overlap like so:
Step 1: Reassign the primary key column (in my case ID) for the layer so it reflects the order in which you'd like the overlaps retained. So the feature with ID = 1 will be left completely intact, feature 2 will be prioritized over feature 3, feature 3 over feature 4, and so on.
Step 2: Run Union, setting the layer as the only input (leaving the Overlay layer empty). This will perform a Union between the layer and itself, resulting in (in my case) 12 features.
Result:
Step 3: Run Delete Duplicate Geometries on the output from Step 2. This reduced the number of features to 7.
Step 4: Run Join Attributes by Location, setting the Base Layer to the output from Step 3, the Join Layer to the original layer from Step 1, the Geometric predicate to "within", and the Join type to "Take attributes from the first matching feature only (one-to-one)". This is where the magic happens, since the first matching feature in each case is determined from the order of the primary key.
Step 5: Finally, run Dissolve, setting the Dissolve field to "ID_2"
, which is the ID of the original features that were joined in Step 4.
Final result: