-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type checking strictness #40
Comments
Related: #38 There is a difference in type handling between ruby liquid and You can do this in ruby liquid: {{ "1" | plus: 1 }} # 2 However, this is not valid in To solve this, a This should still be a valid template to render: {{ "now" | date: "%s" | plus: 86400 | date: "%Y-%m-%d" }} But now it is not. So, the plus, minus and other arithmetic operations managed by However, A universal way to do it is to convert the string into a number explicitly: {{ "1" | int | plus: 1}} # 2 {{ 'now' | date: '%s' | int | times: 1000 | minus: 1800000 }}
# 1634141733000 Now, because the typecasting is handled externally (by the filter It will still be available to do an arithmetic operation in the next minor release (0.7.2) with the output from {{ "now" | date: "%s" | plus: 86400 }} # 1634230267 However, we should direct people to handle the typecasting themselves to avoid confusion. |
Just hit a similar issue. Capture tag results in a string and so it's not possible to do some arithmetic operation after.
I'm totally agree that explicit typecasting specified by the user could be the best solution. |
Yes, at the next release (0.7.2), {% capture lst_size | int %}4{% endcapture %}
{{ 2 | at_most: lst_size }} or use {% capture lst_size %}4{% endcapture %}
{{ 2 | at_most: int(lst_size) }} See also the docs just added: #41 (comment) |
* 🐛 Fix date filter issues (#38, #40) * ✨ Add markdownify for jekyll * 🔖 0.7.2 * 💚 Add markdown dep in CI * ✅ Fix date filter tests * ✨ Add int, float, str and bool as both filters and globals for all modes * 📝 Update docs for builtin typecasting filters/globals. * 📝 Update docs * ✨ Add jekyll filter `number_of_words` * ✨ Add jekyll filter `sort` * ✨ Add jekyll filter `slugify` * ✨ Add jekyll filter `array_to_sentence_string` * ✨ Add jekyll filter `jsonify` * ✨ Add jekyll filters `xml_escape`, `cgi_escape` and `uri_escape`
0.7.2 is released. |
I'm trying to render the following template with
liquidpy
.It should be valid Liquid, it's properly rendered using various online tester tools.
Using
liquidpy
leads to a TypeErroras date are managed via
DateTime
class that only provide plus and minus operations at the moment.I don't know how Liquid handles data types. Is there any way I can force/cast to a specific data type (
int
in this case), "bypassing" Python type checking and so make it works?p.s. I hit this
liquidpy
issue as I'm a user ofShuffle
automation platform.The text was updated successfully, but these errors were encountered: