Backport PR #36444 on branch 1.1.x (BUG: inconsistent replace)
Backport PR #36444: BUG: inconsistent replace
I don't think we want to backport the changes for the black upgrade. will merge this for now. and open a separate PR against 1.1.x using the older version of black to tidy up.