Closed jimbaker closed 1 year ago
In the latest commit, I added support for PEP compliant implementations of Chunk
and Thunk
. I also added a KeyThunk
named tuple implementation to make it more obvious what was done in this projection (in the SQL sense of that) with only conv
and formatspec
.
This feels much better than adding so many caveats about types being is-a, etc. Now they are.
With the changes above, this issue can be closed.
First, the POC is not yet aligned with current PEP work re
Chunk
(as a subclass ofstr
) andThunk
. So it basically is the olderstr
andtuple
model, which worked fine for my purposes for trying out the ideas of the compiler, at the cost of clarity! (But to be clear,str|tuple
is still valid becauseChunk
is-astr
, andThunk
is-atuple
.)With that in mind, let's try some things out after doing the various installs:
Also when I write code here, I'm going to use
Chunk
, where I have done the following(not right, but raw strings vs strings is just a question of doing that decode, so good enough for now, and I will use interchangeably).
Note that anything that takes
*args: str|tuple
or*args: Chunk|Thunk
is a valid tag function. This is super useful, as we can use it to figure out what is going on withmake_key
without having to call through a fairly complex chain, as inThe key insight, so to speak, is that we only distinguish based on the string chunks and the
conv
/formatspec
, if set at all. The argument here is that any interpolation forgetvalue
and itstext
is equivalent in how it can be used in the the template, so we always make thoseNone, None
in the key.Lastly, here's a better version of
make_key
:Note that for
case
statements, there's no instantation of the class - this is equivalent to sayingisinstance(arg, Chunk)
, etc.The return value might be a bit unexpected, but hopefully this analysis makes it clearer. So it's
tuple
, because we need something hashable (nolist
) for using as a key, but it's of aChunk | tuple
. Sotuple[Chunk | tuple, ...]
Chunk | Thunk
, becausegetvalue
andtext
(or whatever we call the expression text) ofThunk
cannot beNone
.Let's also look at
html
:The first time through, it compiles the function, and has the nice side effect that when it compiles, it prints the code. Also we can do this:
Second time through, no printing, because it has cached things: