python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
444 stars 159 forks source link

Add __repr__ to LazyString #106

Closed MichiK closed 8 years ago

MichiK commented 8 years ago

I work with lazy strings a lot and I have a task that uses them extensively and also produces some logging output containing them. In older versions of Flask Babel, I could simply throw a function's arguments into my logger and get a useful result. E.g. a list of tuples containing some lazy strings looked like this in the logfile:

[(l'0 to 49', 0, 0.0), ...]

The same list became this since the update:

[(<flask_babel.speaklater.LazyString object at 0x7f0d859e5a20>, 0, 0.0), ...]

Of course, I could wrap str() around every lazy string I want to log, but in case of a list, a simple log(foo) would become log([str(elem) for elem in foo]).

Adding a simple __repr__ method (like the one of _LazyString of the old, standalaone speaklater) to the LazyString class makes life a lot easier here.

MichiK commented 8 years ago

Ok, I just looked at the old speaklater code and did the same here. I agree on the try/catch but I was not really able to decide if this is legit if it occurs and should be catched. Actually, I have seen lazy strings with "<_LazyString broken>" before, but I think in the end it does not really matter since such things are usually only a symptom of another problem.