[Python-Dev] Backporting PEP 3101 to 2.6 (original) (raw)
Eric Smith eric+python-dev at trueblade.com
Fri Jan 11 17:43:40 CET 2008
- Previous message: [Python-Dev] Backporting PEP 3101 to 2.6
- Next message: [Python-Dev] distutils.cygwinccompiler: invalid executable for interpreters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Steve Holden wrote:
Nick Coghlan wrote:
To elaborate on this a bit (and handwaving a lot of important details out of the way) do you mean something like the following for the builtin format?:
def format(obj, fmtspec=None): if fmtspec is None: fmtspec='' result = obj.format(fmtspec) if isinstance(fmtspec, unicode): if isinstance(result, str): result = unicode(result) return result Isn't unicode idempotent? Couldn't if isinstance(result, str): result = unicode(result) avoid repeating in Python a test already made in C by re-spelling it as result = unicode(result) or have you hand-waved away important details that mean the test really is required?
This code is written in C. It already has a check to verify that the return from format is either str or unicode, and another check that fmt_spec is str or unicode. So doing the conversion only if result is str and fmt_spec is unicode would be a cheap decision.
Good catch, though. I wouldn't have thought of it, and there are parts that are written in Python, so maybe I can leverage this elsewhere. Thanks!
Eric.
- Previous message: [Python-Dev] Backporting PEP 3101 to 2.6
- Next message: [Python-Dev] distutils.cygwinccompiler: invalid executable for interpreters
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]