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

Eliminating undefined parameters entirely by NeverUndefined #1924

Closed
wants to merge 3 commits into from

Conversation

James4Ever0
Copy link

@James4Ever0 James4Ever0 commented Jan 3, 2024

This pull request is done by changing two files in the source code directory. It integrates the NeverUndefined class and make it usable by:

import jinja2
# access by: jinja2.NeverUndefined

This will raise exception for the following template, while StrictUndefined will not:

{% macro test(a, b, c) %}
a macro with three parameters but not used
{% endmacro %}

{{ test() }}

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@James4Ever0 James4Ever0 changed the title Eliminating undefined function calls entirely by NeverUndefined Eliminating undefined parameters entirely by NeverUndefined Jan 3, 2024
@James4Ever0 James4Ever0 changed the title Eliminating undefined parameters entirely by NeverUndefined Eliminating undefined parameters entirely by NeverUndefined Jan 3, 2024
@ThiefMaster
Copy link
Member

did you create the PR using an LLM? the code and comments in there surely look like that's the case...

You also don't explain when your code would actually be useful...

@James4Ever0
Copy link
Author

James4Ever0 commented Jan 3, 2024

did you create the PR using an LLM? the code and comments in there surely look like that's the case...

You also don't explain when your code would actually be useful...

This code is half a year old and I do it for fixing this long standing error.

I want to explain but my memory is fuzzy. It is useful.

About your suspicion, I can tell that I had the feeling too. I am building a project named Cybergod, which can control mouse and keyboard and possibly do stuffs like browsing Github, making pull requests :)

The comment in the code is to indicate what were passed as *args and **kwargs at that location. I reason about the *args are not so easy to be parsed, neither as the **kwargs.

I decide to collect the info from *args and **kwargs as error message, and raise Exception right after __init__, not waiting for invocation, unlike StrictUndefined.

@davidism
Copy link
Member

davidism commented Jan 3, 2024

See issue for slightly longer explanation. If you think this is generally useful to others, you can create an extension, but there's nothing requiring it to be in Jinja core.

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

Successfully merging this pull request may close these issues.

Introducing NeverUndefined
3 participants