[1.7.x] Fixed #23492 -- Restored F.__deepcopy__.

This reverts commit 3a66035107a640c4905f0a5f247a45f32dbe16d7.
A regression test was also added.

Backport of d63ac5b595694c44ed8a64d782a177d2f92125d9 from master.