Quote:
Originally Posted by un_pogaz
It's a pity but it's "normal" because you use the function as Calibre calls it itself. It's a point to underline in their doc and usage.
|
Je comprends la française.

For conversations between us feel free to write in French it if you think you will be clearer. I can write in French if needed, but my grammar and vocabulary aren't good. Des faux amis me donne beaucoup de problèmes.
I was just writing a post to say that overnight I found convincing arguments for this ability.
- There are people with a library of stored functions and/or templates. This lets the person use their library, converting to python as and when needed.
- Some of the built-in functions are complicated, for example list_re_group(). No need to bother to rewrite these.
- Some built-in functions would be hard to rewrite, for example template().
I looked at your code and it is quite elegant. Some questions:
- Why use object.__setattr__() in FormatterFuncsCaller __init__ instead of
Code:
self.formatter = formatter
- What is the point of the recursive get_attribute() in FormatterFuncsCaller (line 892)? As far as I can see an instance of FormatterFuncsCaller doesn't have any attributes other than .formatter.
EDIT: Never mind. It must be there to return .formatter and .call, at least
- What about not requiring the trailing '_' if there is no collision with a python keyword? FormatterFuncsCaller.__get_attribute__() could check the name with and without the underscore.
- Do we want the 'hidden' attributes .formatter and .funcs in PythonTemplateContext.attrs_set? I think these aren't something the user should use or see. No need for them to be in the output of __str__().
- This error exception should be simpler:
Code:
EXCEPTION: Error in function evaluate on line 4 : AttributeError - 'FormatterFuncsCaller' object has no attribute 'a_python_template'
Perhaps something like this:
Code:
EXCEPTION: Error in function evaluate on line 4 : AttributeError - no function 'a_python_template' exists
- I am a little concerned about recursion in processing templates, but that can happen today. Oh well.
There are a few typos in comments, and a few cases where line spacing doesn't follow Kovid's rules. I can clean those up once we are satisfied with the implementation.