[eudsl-python-extras] drop support for generics for py < 3.12 #236
+620
−894
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After much consternation and flaggelation, I've decided we can't/shouldn't support generics for python < 3.12. The context/reason is that I thought I had robust support for just plain
TypeVars as globals (and in the closure) but recently I've realized that that support is not robust.In the weeds: the "generic" kernel instantiation effectively mutates the
TypeVarand thus when theTypeVaris a global, multiple instantiations of the same kernel (with different concrete params) will race (on that globalTypeVar).TypeVars in the closure don't suffer from this because we copy thebody_builderand its closure when instantiating the kernel. In 3.12 (when using the bracketsdef fun[M, N, ...]syntax) theTypeVars are always in the closure1. I tried to figure out somehow to move globals into closures but failed and decided it's not worth the effort anyway.Note, the added test (
test_generics) is gated behind 3.13 because generics default value assignment is a 3.13 feature and the 3.12 parser will choke on it, but everything else works in 3.12.Footnotes
That's actually a CPython implementation detail - there's a compiler transform which rewrites the function into a closed over function with those TypeVars in its closure. ↩