Interpolation type map for tooling#114
Conversation
Hah, yeah. The non-strict types, all of which are basically
Primarily the intent of these types would be documentation for tool developers. If, for instance, Astral decided to support type checking of t-string HTML content in That said, I see you did use some non-strict types in |
My rough idea was that a tool would consume the "type map" and use that type map together with a TDOM-aware parser to type check each appropriate Template: [tool.lintingtool.exts.tdom]
path_to_type_map = "src/myapp/tdom_config.py"
version = 0.1
annotated_marker="html+tdom"type TDOM = Annotated[Template, "html+tdom"]
invalid = b'abc' #bytes
check_t: TDOM = t"<div>{invalid}</div>"
Since the Templates all just track |
|
I think it's a good possible approach to keep in mind for down the road. Thinking specifically about extending "General mechanism for third parties to express string grammars + type maps" sort of feels like a PEP in the making but it is fraught with peril. |
|
So my current hand-wave crazy idea: create a new library ( Then build an CLI ( |
|
Your crazy idea would feel exceptionally well in my crazy idea: an agent that runs locally in a small model by moving more of the work out of the LLM. I'm pretty far along on it and have some machinery in a similar (but more primitive) ballpark. |
I just figured each format would need its own "tailored" "tnode-ifier" that parses the content and identifies those "slots". I think that is what |
Yeah, that's the right day zero approach. My "crazy idea" is more like day 1,000. In any case, I'm still not sure I understand the value of an "interpolation type map" in the "tailored" world. Tailored tools need to know the names of the possible slots; at that point, why not also know their expected types?
Yes, that's the idea. There are obvious limitations here (can't help you much when there's a |
case 1: You still want to catch type errors but you want to allow other types You have a custom handling for case 2: You want to use a completely different type for an extension Another example might be that the components are not callables at all (ie. the fact that protocols satisfy that seems like a total accident), like maybe you want to just use a fixed marker. #.... some sort of component marker for a custom component processor to handle
@dataclass(frozen=True, slots=True)
class ComponentMarker:
name: str
Header = ComponentMarker('Header')
# some sort of configuration a tailored tool reads in
from tdom.types import default_template_strict_type_map, ComponentInterpolationValue
# Here we use ComponentInterpolationValue as a key so the general "slots" are well defined but the type has changed
template_type_map = default_template_strict_type_map | {ComponentInterpolationValue: ComponentMarker}
# using it in a template doesn't throw redlines/yellowlines
example_t: Annotated[Template, "html+tdom"] = t"<{Header}>somsfjsakldjflkasdf</{Header}>"
I did start on a prototype but it is more of a "script" at this point: #122 |
|
Perhaps we should close this and move to discussion! |
|
@ianjosephwilson Sorry for using GitHub as a DM service. We booked the open space: t-string-apalooza S-3 - Saturday May 16, 2:00 PM PDT |
|
Perfect, thanks @pauleveritt |
This is just a draft / concept of a way we could specify supported types that tooling could use to give feedback to users about what they are plugging into
TDOMtemplates. This is sort of what I felt like we have been working towards:TNode,TAttribute,...default_template_type_map(this thing)Obviously having
objectall over the place isn't great so I tried to take a stab at a more strict set of types that would require other types to be preprocessed either before involvingTemplateat all or with a conversion or format spec.I can imagine cases where you'd want to define some common types you are putting into templates and converting to strings yourself so there would probably be someway to extend this.