3 ms·
You'd have to pay a lot. Jokes of mine like https://github.com/dutc/rwatch https://github.com/dutc/rwatch and https://github.com/dutc/didyoumean https://github
by jamesdutc 11y ago
You'd have to pay a lot.
Jokes of mine like https://github.com/dutc/rwatch https://github.com/dutc/rwatch and https://github.com/dutc/didyoumean https://github.com/dutc/didyoumean and https://bitbucket.org/dutc/astexpr https://bitbucket.org/dutc/astexpr are examples of adding major features to the CPython interpreter at run-time. It works fairly well in practice. It ends up looking like a `__future__`-import pragma that has interpreter lifetime scope rather than file scope.
`__future__` imports cannot be undone within the same file -- after all, they're pragmas scoped at the file level, not actual imports -- and it would make sense for these backported features to behave similarly, though at the scope of the interpreter's lifetime. That might not do what you want.
As you'd expect, the most superficial of Python 3's new features (syntax changes, `raise from`, &c.) would be easiest to backport. The bulk of the difficulty would be in merging those changes into Python 2.7. Making the result hot-loadable would be just as easy as in `dutc-rwatch`, though being able to toggle features on-and-off independently would require combinatoric effort with the naïve approach. You'd need to do something smarter.
All in all, it's wholly possible to do what you want, and you probably have the skill to even do it yourself.
I'd happily do the work myself, but only for lots of money. Unfortunately, the burden of both certifying the resulting interpreter as correct and of maintaining this fork would be large.
And then when you're on-boarding some fresh new post-grad you've just hired into your research group:
"Oh, we use Python 2.8 here. That's what we call Python 2.7 with an unsupported collection of modules that mutate the currently running interpreter to backport features from Python 3. Don't worry; it only breaks in ways that no one outside of this office will ever have a chance of ever understanding or helping you debug."
- jamesdutc 11y agoOh, I should also mention that I found a way to embed Python interpreters within themselves. I have a couple of different ways to do it. Here's one: https://gist.github.com/dutc/eba9b2f7980f400f6287 https://gist.github.com/dutc/eba9b2f7980f400f6287 Here's another: https://gist.github.com/dutc/2866d969d5e9209d501a https://gist.github.com/dutc/2866d969d5e9209d501a I've given, like, a million conference talks about this. Better than creating some horrible Python 2.8 hybrid would be funding (or convincing me to volunteer to do) the work of completing this bridge. This involves writing 2/3 and 3/2 PyObject shims and figuring out some GIL and GC issues. Then, within a given host interpreter, you'd be able to execute modules within a guest interpreter of whatever Python version you want. With the shims and the bridge work, you'd be able to interact with these objects seamlessly from host-to-guest and guest-to-host.
- fernly 11y agoAren't there issues at the bytecode level? I've been studying bytecode and ceval.c and I know there are significant differences in the bytecode set, as well as in the code object and function object. So what would a "Python 2.8" compile phase generate? Would the huge switch statement in ceval.c have to have a whole new layer of if-logic in it?