jimbaker / tagstr

This repo contains an issue tracker, examples, and early work related to PEP 999: Tag Strings
51 stars 6 forks source link

Add section on return types, clarify dotted names, and process comments #45

Closed pauleveritt closed 2 months ago

pauleveritt commented 2 months ago

Return types don't have to be a string, so feature this point. Allow dotted names and expressions as tag names. Remove two unneeded sections and move = discussion up.

pauleveritt commented 2 months ago

@lysnikolaou I believe this addresses the points raised in your PR. @davepeck updated section on dotted names.

Still has one TODO for @jimbaker to provide a protocol class example for what an HTML response might be shaped as.

pauleveritt commented 2 months ago

Other than @davepeck suggestion, all is processed and updated.

Next step: send a PR to the repo and nudge Eric Snow, who said he'll look at it then. After that, announce for public discussion.

But before then: @lysnikolaou perhaps you want a chance to think more about it during the work to rebase the branch on main? (Not the bigger work on concrete, C implementations of types.)

pauleveritt commented 2 months ago

@jimbaker and I had a working session today on the tutorial. Two changes I just pushed:

The protocol would now look like:

@runtime_checkable
class HTML(Protocol):
        tagname: str
        attrs: dict[str, Any]
        children: Sequence[str | HTML]

As a note, when we talk about implementations of the protocol, we will use HtmlNode.

jimbaker commented 2 months ago

Relevant to https://github.com/jimbaker/tagstr/blob/pe-process-nits/pep.rst#tag-function-arguments and came up in the tutorial discussion with @pauleveritt:

def mytag(*args: str | Interpolation) -> Any 

is often what we will see in practice for any typed tag functions. This is because most tag functions will not need to use Decoded, since they don't need access to the raw attribute. Because the most common pattern of usage is with structural pattern matching, it's likely these signature types will also be seen in the function body, that is

match arg:
    case str() as s:
        ...
    case Interpolation() as i:
        ... # use .getvalue, possibly other attributes

The other thing is that the return type above would be generally narrowed from Any, such as HTML, QuerySet, str, ... - depends on the DSL.

pauleveritt commented 2 months ago

Another two comments. Sorry for the constant back and forth, I'm just seeing more things as I parse the text more times.

Thanks very much for doing this.

On an unrelated note, I've pushed https://github.com/lysnikolaou/cpython/tree/tag-strings-rebased which is Guido's implementation on top of main. Will start addressing any remaining things this week.

That's great news. If you think you're wrapped up on that, we'll update the Docker file and the WASM build that we're using for a JupyterLite demo notebook.

Also, it might be a good idea for us to have a chat room somewhere for a quicker feedback cycle and to post updates as we get closer to the PEP announcement.

What's your preference? We can use whatever you'd like. Also: Jim and I had a long working session on Saturday morning (eastern) for the tutorial and the fdom work he's been doing.

lysnikolaou commented 2 months ago

If you think you're wrapped up on that, we'll update the Docker file and the WASM build that we're using for a JupyterLite demo notebook.

There's still stuff left to do. I'll spend time on it this week, we can probably update Docker/WASM and the PEP afterwards.

What's your preference? We can use whatever you'd like.

No preference. Just thought that a more chat-like interface might help iterate a bit faster. Maybe Discord?

pauleveritt commented 2 months ago

There's still stuff left to do. I'll spend time on it this week, we can probably update Docker/WASM and the PEP afterwards.

As it turns out, we have a WASM challenge with Pyodide only support 3.12. We can wait until you're wrapped up for Docker.

No preference. Just thought that a more chat-like interface might help iterate a bit faster. Maybe Discord?

Discord is fine with me. Group chat on the Python Discord?

davepeck commented 2 months ago

the fdom work he's been doing

It feels like a natural fit with this PEP to also build a library of common tags (html, etc.) — sounds like this is something that's underway?

PS: I have the rebased branch working locally. This is fun:

>>> def tag(*args):
...     return args
...     
>>> tag"hello{x}world"
('hello', (<function <lambda> at 0xffffa872d6d0>, 'x', None, None), 'world')
pauleveritt commented 2 months ago

@lysnikolaou @davepeck Let's get a chat going on the Python Discord. I'm pauleveritt over there. I just talked to Jim, he said he'd get Discord set up and join in.

Dave, send me an email (pauleveritt@me.com) and I'll connect you to the other work that's been going on. (Don't want to make it noisy over here.)