Skip to content

unify contextfilter and contextfunction markers #1381

@davidism

Description

@davidism

contextfilter and contextfunction (and other decorators) do the same thing, the only difference is the name of the internal variable they use. I'm not clear what the history on this was, maybe at some point there were actual code differences that warranted the distinction. But that doesn't seem to be the case anymore. The current names are hard to understand (unless you already know the terms, it's hard to know that "evalcontextfilter" is "eval context filter"), and it's easy to apply the wrong decorator to a given filter/test/function.

Even after digging into the code, I still make the mistake of trying to use contextfunction on a filter, or contextfilter on a function. If you use the wrong one, the compiler/runtime completely ignores it and you get an unhelpful "wrong arguments" error from Python later, but there's no real difference behind the scenes.

Code in environment, nodes, compiler, and asyncsupport look at these names. I think we should unify on a single set of readable names, maybe uses_context, uses_eval_ctx, and uses_environment, or possibly a single variable like uses = "context". The existing attributes aren't public API, but just in case we can also check for the old names and issue a deprecation warning. Deprecate the old decorators in favor of pass_context, pass_eval_ctx and pass_environment.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions