python: clean up LINKFORSHARED inreplace

Fixes #20860.