'%d' % foo and '%f' % bar working, on some corner cases[1]:“StringFormatter: '%d' and '%f' support for the __int__ and __float__ protocol respectively.
The implementation is more convulted than it should be, because we have PyString implementing __float__ and __int__ at the "java level" but not at the "python level". For string formatting, only "python level" __float__ and __int__ must be
supported.
Also, now that __int__ can return a PyLong, this case needs special care. Basically formatInteger now can call formatLong if a PyLong is found as the result of __int__. Then, as formatLong can also be called from formatInteger, __hex__, __oct__ and __str__ conversions were moved inside formatLong.
Finally, test_format_jy was changed to stop checking that we don't support big floats on '%d' (CPython doesn't, but that seems a limitation of the specific implementation and I can't imagine a program that could break on Jython because we *support* it).”
Python is wonderful, but there are a lot of details which make it tricky when implementing it. Nice to see that, when we play the role of Python users, we aren't exposed too much to this subtleties. In fact, I'd say that it is one of the languages with the better "user interface" I've seen.
[1] Naturally, I find this corner cases when running and testing the Django codebase. Well, that's one of the points of my SoC project: Test how CPython-compliant Jython is, and fix it when it isn't :).


0 comments:
Post a Comment