A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-August/055575.html below:

Allow str() to return unicode strings

[Python-Dev] Revised PEP 349: Allow str() to return unicode strings [Python-Dev] Revised PEP 349: Allow str() to return unicode stringsNeil Schemenauer nas at arctrix.com
Tue Aug 23 17:21:57 CEST 2005
On Tue, Aug 23, 2005 at 10:46:36AM +0200, Wolfgang Lipp wrote:
> one point i don't seem to understand right now is why it says in the
> function definition::
> 
>      if type(s) is str or type(s) is unicode:
>          ...
> 
> instead of using ``isinstance()``.

I don't think isinstance() would be okay.  That test is meant as an
optimization to avoid calling __str__ on str and unicode instances.
Subclasses should still have their __str__ method called otherwise
they cannot override it.

> the code as it stands means i have to remember that *in this special
> case only* (when deriving from ``unicode``), i have to add a
> ``__str__()`` method myself that simply returns ``self``.

Ah, I see that unicode.__str__ returns a str instance.

> then of course, one could change ``unicode.__str__()`` to return
> ``self``, itself, which should work. but then, why so complicated?

I think that may be the right fix.

  Neil
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4