Over 32 posts spanning 2 years, this is the final post in my blog series on Python's syntactic sugar. I had set out to find all of the Python 3.8 syntax that could be rewritten if you were to run a tool over a single Python source file in isolation and still end up with reasonably similar semantics (i.e. no whole-program analysis,
globals() having different keys was okay). Surprisingly, it turns out to be easier to list what syntax you can't rewrite than re-iterate all the syntax that you can rewrite!
- Integers (as the base for other literals like bytes)
- Function calls
- Function definitions
All other syntax can devolve to this core set of syntax. I call this subset of syntax the Minimum Viable Python (MVPy) you need to make Python function as a whole. If you can implement this subset of the language, then you can do a syntactic translation to support the rest of Python's syntax (although admittedly it might be a bit faster if you directly implemented all the syntax 😉).
If you look at what syntax is left, it pretty much aligns to what is required to implement a Turing machine:
- Read/write data (
:=, and integers)
- Make decisions about data (
- Do things to that data (everything involving defining and using functions)
You might not be as productive in this subset of the language as you would be with all the syntax available in Python 3.8 (and later), but you should still be able to accomplish the same things given enough time and patience.
Since the initial publication of this post on 2022-08-14, I was able to unravel even more syntax than I initially thought. This post has been updated to reflect those later realizations.