Repository navigation
Print builtin classes, loop bound methods and imported modules as Jinja2 does (0305, 0309) #721
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89cfed2
Print the builtin classes and loop's bound methods as Python does (0305)
claude 6b884de
Bind an imported module as Jinja2's TemplateModule object (0309)
claude 3590bab
Keep the hand-wrapped repr test out of clang-format (0305)
claude ffcf81b
Include the headers the module test uses (0309)
claude 118d961
Keep one TemplateModule object per module, so shared imports are equa…
claude 4d9e639
forceescape, striptags and safe take an imported module's __html__ (0…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| status: open | ||
| priority: low | ||
| area: parity | ||
| depends: [0305] | ||
| touches: [src/statements.cpp#LoopCycleCell] | ||
| --- | ||
| # A kept `loop.cycle` prints `?` for the length of a lazily filtered loop it broke out of | ||
|
|
||
| **Problem.** Found doing 0305. A `loop.cycle` or `loop.changed` callable prints as Jinja2's bound | ||
| method, `<bound method LoopContext.cycle of <LoopContext 1/2>>`. The callables share a cell with | ||
| their loop (`LoopCycleCell`), not the loop itself: a callable that kept the loop would make the | ||
| loop collect the rest of its items when it ends (the `use_count` check in `ForStatement`), which | ||
| runs the loop filter for items Jinja2 never filters (`statements.loop_cycle_stored_filtered_break` | ||
| raises in the filter then). So a callable kept past a `break` out of a loop whose length was not | ||
| known yet, a lazily filtered one (`for x in l if ...`), has no items left to count, and prints the | ||
| length as `?`. Jinja2 counts them when the repr is taken, which also runs the filter then (and | ||
| raises there if the filter does). Pinned by `statements.loop_cycle_repr_after_break_lazy`. | ||
|
|
||
| **Proposal.** Keep what the loop needs to fetch its rest (its enumerator over a list the cell | ||
| keeps alive, and the filter's expression with a context of its own) in the cell when a callable | ||
| shares it at the loop's end, and collect the rest on the first repr. Only worth it if a template | ||
| in the wild prints such a callable; otherwise mark the line deliberate. | ||
|
|
||
| **Done when** the line is gone from `test/parity/divergences/statements.txt` or marked deliberate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| status: open | ||
| priority: low | ||
| area: parity | ||
| depends: [0309] | ||
| touches: [src/testers.cpp#IsEscapedMode, src/filters.cpp#Join, src/serialize_filters.cpp#XmlAttrFilter] | ||
| --- | ||
| # `m is escaped` of an imported module | ||
|
|
||
| **Problem.** Found doing 0309. `{% import 'lib' as m %}` binds Jinja2's `TemplateModule`, whose | ||
| `__html__` gives its output as Markup. Since 0309 the module object prints that way under | ||
| autoescape (markup.h, `IMapAccessor::GetStrValue`), but the `escaped` test (testers.cpp, | ||
| `IsEscapedMode`) asks only Markup strings and host objects, so `{{ m is escaped }}` is False where | ||
| Jinja2 says True. Pinned by `loader.module_object_is_escaped`. testers.cpp belonged to parity | ||
| batch 2 group A when this was found, so it was not fixed in 0309's PR. | ||
|
|
||
| Two more sites take str() of the module where Jinja2 takes `__html__` under autoescape (found by | ||
| the 0309 verifier, no corpus case yet): `{{ [m]|join }}` escapes the output twice | ||
| (`&lt;i&gt;`, Jinja2 `<i>`), and `{{ dict(a=m)|xmlattr }}` escapes it once | ||
| (`a="A<b>B"`, Jinja2 `a="A<b>B"`). | ||
|
|
||
| **Proposal.** In `IsEscapedMode`, and in join's and xmlattr's Markup checks, treat a map whose | ||
| `GetStrValue()` is set as having `__html__`, as `host::IsMarkupLike` does for host objects; add a | ||
| corpus case for each. | ||
|
|
||
| **Done when** the line is gone from `test/parity/divergences/loader.txt`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.