[IronPython] Id: 356 unicode throws when creating a Unicode string from an invalid Unicode string (was Re: Importing embedded .py files)

Sanghyeon Seo sanxiyn at gmail.com
Thu Jul 6 09:23:38 CEST 2006


2006/7/6, JoeSox <joesox at gmail.com>:
> 221:        if isinstance(s, unicode):
> 222:            s = str(s)

Eh, some Python codes assume "isinstance(s, str)" and "isinstance(s,
unicode)" can't be both true. IMO this should be discouraged. For
example, one serialization library registers serialization handlers
for str and unicode, and raises(!) if a handler is registered twice
for the same type. Of course this won't work in IronPython.

The assumption also doesn't hold in Jython. str and unicode are
functions, not types in Python 2.1, which Jython implements. To test,
try type('') == type(u'').

Seo Sanghyeon



More information about the Ironpython-users mailing list