Skip to content
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

Documentation error in first code block for Template.stream(...) method #1515

Closed
sthagen opened this issue Oct 18, 2021 · 1 comment
Closed
Labels

Comments

@sthagen
Copy link

sthagen commented Oct 18, 2021

Reproducing the Documentation Bug

  1. Go to https://jinja.palletsprojects.com/en/latest/api/#jinja2.Template
  2. Type into the commands of the first code example block
  3. The assert on the first next(stream) call should fail

As is:

>>> template = Template('Hello {{ name }}!')
>>> template.render(name='John Doe') == u'Hello John Doe!'
True
>>> stream = template.stream(name='John Doe')
next(stream) == u'Hello John Doe!'
True
>>> next(stream)
Traceback (most recent call last):
    ...
StopIteration

Suggested:

>>> template = Template('Hello {{ name }}!')
>>> template.render(name='John Doe') == 'Hello John Doe!'
True
>>> tream = template.stream(name='John Doe')
>>> next(stream) == 'Hello '
True
>>> next(stream) == 'John Doe'
True
>>> next(stream) == '!'
True
>>> next(stream)
Traceback (most recent call last):
    ...
StopIteration

Environment was:

  • Jinja2 v3.0.2 per pypi
  • python 3.9.2 (should not really matter)
  • I did not use the u prefixes for string literals - I rarely do these days ...
@davidism
Copy link
Member

davidism commented Nov 9, 2021

That example isn't really relevant to creating a template objects, so I've removed the example and reworded the docs a bit.

@davidism davidism closed this as completed Nov 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants