Replies: 3 comments 5 replies
-
Very nice! I agree, the |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for taking the time to write down the ideas/suggestions!
That's great to hear! :)
Very much agree! Feel free to send a PR if you have something in mind, otherwise I will add that when I get around to it.
We use this syntax extensively in our code base and find it succinct and nice but yes, it is a matter of taste. Will think about the first example, it may be too much to use it there since it may not be obvious how it works and could be off putting. Regular attributes are probably clearer to show of there.
Good point. I think it is generally a bad idea to shadow builtins but that it is fine in this particular case. This is only a potential problem in the implementation of the function, not for the caller. In the case of htpy it is fine since we only deal with
Pythons inline if still read backwards to me and it looks better in JS just because of the ordering. I am not keen on including these in htpy since it feels out of scope to introduce new custom control flow functions. I think htpy should not make decisions about control flow but anyone is free to use their own helpers for this. I tried to express this at https://htpy.dev/#philosophy - the idea is to just use Python. I would maybe have used another syntax for Python inline if it was up to me but we are kind of stuck with it now for good or worse and I think it is better to stick to it.
Did you consider Python builtin map? https://docs.python.org/3/library/functions.html#map ul[
map(lambda animal: li[animal], ["Cat", "Dog", "Horse"])
]
This would be interesting if it was possible. But I am also not overly concerned about typing elements/attributes according to the HTML spec. Custom elements is a thing and people (ab)use custom attributes for so many things typing them is impossible. In our company we are heavy users of custom elements, Shoelace, Alpine.js and htmx. Restricting allowed element names/attributes would not be helpful and trying to add types would also be very hard. That said, ff it was possible to add typed attributes in useful way, that would be great! |
Beta Was this translation helpful? Give feedback.
-
I will bring a suggestion!
I think it might make it more difficult for the user if they didn't know all the keywords by heart, that it sometimes would work to use an
Actually no, I haven't actually used it, have made my own utilities for this kind of stuff. Thank you for bringing it to my attention, useful. For this particular purpose, it feels a bit backward to me though. Its the same with the list comprehension/for loops in python. I would prefer if the iterable came first and the callback after.
I will look into this one a bit at some point |
Beta Was this translation helpful? Give feedback.
-
I've been playing around building some very similar lib. Used some different python tricks to get similar syntax, but instead of the getitem trick, used overloaded functions that sometimes returned another function, other times just a node. This is the working syntax:
This was also valid (without attrs)
I like your approach (better) and will play around with it.
Way to go!
Beta Was this translation helpful? Give feedback.
All reactions