That’s what --overwrite
does, no need to remove them first.
You can reduce the danger by doing
sudo pacman -Syu --overwrite "usr/lib/python3.12/site-packages/*"
so it will overwrite only in that dir.
(I wonder if pacman uses ** like bash does,
and whether pacman needs ** instead of * to overwrite in sub-dirs… ?)
or in any Linux distro.
Packages installed with pip have a “dist-info/INSTALLER” file,
which contains only the word “pip”.
(eg: ~/.local/lib/python3.12/site-packages/rst2html5-2.0.1.dist-info/INSTALLER
)