What is the best way to issue deprecation warnings for deprecated variables 
when they are used in a user created template?

We maintain project in which users create their own themes using Jinja 
templates based upon a documented list of variables we pass to the template 
context,  Suppose the following variables have existed in our project which 
have been used by our users in user created templates: "foo_name", 
"foo_bar", "foo_baz".

However, as part of a refactor (for reasons not relevant to this 
discussion), we are renaming those variables to: "foo.name",  "foo.bar", 
"foo.baz".

As an intermediary measure, we would like to pass both the old and new 
variables to the context for a version or two of our project, with a 
deprecation warning to be raised (and logged) if a template accesses any of 
the "old" variable names. However, the template should still render 
correctly until some future version when the old variable names are 
removed. What is the best way to issue those warnings?

I explored the Undefined API, but that seems to be for "undefined" 
variables and these are still defined, just deprecated. And I don't want to 
alter the behavior for any other undefined variables which are not in our 
predefined list. 

Then I used a subclass of the Context class which overrides the `resolve` 
method. If the `key` name is in the list of known deprecated variables, 
then a warning is logged. In either case, the parent classes `resolve` 
method is then called and everything works as before. This works, but 
causes the same warning to be issued for every page that the template is 
used. If a user has a lot of pages, that is a lot of warnings. Anyone have 
any better suggestions and/or know of any existing working solutions.

Waylan

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pocoo-libs+unsubscr...@googlegroups.com.
To post to this group, send email to pocoo-libs@googlegroups.com.
Visit this group at https://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to