fix races when initializing `#[pyclass]` type objects
This is split from #5223 as a follow-up which enacts the changes to LazyTypeObject to use PyOnceLock, and in the process fixes #5211
Only the second commit is new, the rest is in #5223.
CodSpeed Performance Report
Merging #5341 will not alter performance
Comparing davidhewitt:disallow-races (2046f74) with main (6af9595)
Summary
✅ 98 untouched
@davidhewitt would you like a hand getting this rebased and updated for 0.28?
Sure thing, the main thing that got it stuck was https://github.com/PyO3/pyo3/pull/5341#discussion_r2300036538 where someone needs to examine the semantics of class attribute initialization and decide what we want to guarantee.
@davidhewitt FYI - I just force-pushed a rebase to this branch. The only nontrivial bit was the fix for the conflict with https://github.com/PyO3/pyo3/commit/85e6507f261e8a288fc699cb25bd6fd6986d2101#diff-f97e0150474170093c7508d4ac482d2ab24d5325468b860c85aa4da13024917a, but I think I have it right given that the tests pass for me.