[Python-ideas] Alternative Unicode implementations (NSString/NSMutableString)

Jim J. Jewett jimjjewett at gmail.com
Tue Jul 18 18:35:11 EDT 2017

Ronald Oussoren came up with a concrete use case for wanting the
interpreter to consider something a string, even if it isn't
implemented with the default datastructure.

In https://mail.python.org/pipermail/python-ideas/2017-July/046407.html
he writes:

   The reason I need to subclass str: in PyObjC I use
   a subclass of str to represent Objective-C strings
   (NSString/NSMutableString), and I need to keep track
   of the original value; mostly because there are some
   Objective-C APIs that use object identity. The worst
   part is that fully initialising the PyUnicodeObject fields
   often isn’t necessary as a lot of Objective-C strings
   aren’t used as strings in Python code.

The PyUnicodeObject (via its leading PyASCIIObject member) currently
uses 7 flag bits including 2 for kind.  Would it be worth adding an
8th big to indicate that string is a virtual subclass, and that the
internals should not be touched directly?  (This would require
changing some of the macros; at the time of PEP 393 it Martin ruled
YAGNI ... but is this something that might reasonably be reconsidered,
if someone did the work.  Which I am considering, but not committing


More information about the Python-ideas mailing list