Re: [Pyobjc-dev] NSString & mutability
Brought to you by:
ronaldoussoren
From: David E. <epp...@ic...> - 2003-02-04 20:49:36
|
On 2/4/03 3:38 PM -0500 bb...@ma... wrote: > On Tuesday, Feb 4, 2003, at 15:21 US/Eastern, Just van Rossum wrote: >> Someone on comp.sys.mac.programmer.help suggested a trick to find out >> whether an NS[CF]String is mutable or not: by comparing classForCoder >> to >> NSString. Nifty. >> >> This allowed me to patch objc_support.m so it only converts immutable >> strings to Python strings: > > Nice hack, but.... > > What about all the code that might return a mutable string depending on > how the developer exercises the API? Are you willing to assume that > every getter and setter that internally makes a immutable copy of the set > string value? i.e. that... If some code is going to do that, it is certainly worse to convert the mutable string to a python string, because then the converted string wouldn't see any mutations that might be made later on the objc side. I could live with not converting any NSStrings, as long as the Python side views the unconverted NSString as something that's mostly interchangeable with real str's. If there is some code that really needs its argument to be a str, one could always explicitly convert with str(), but I'd like such conversions to be rare. Just like in pure Python, where most of the time anything that obeys the list or iterator protocol can be passed in place of a list, but sometimes you need an explicit call to list(). -- David Eppstein UC Irvine Dept. of Information & Computer Science epp...@ic... http://www.ics.uci.edu/~eppstein/ |