This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients ammar2, benjamin.peterson, ezio.melotti, lemburg, pitrou, steven.daprano, vstinner
Date 2016-07-06.01:34:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1467768893.88.0.743546082022.issue27458@psf.upfronthosting.co.za>
In-reply-to
Content
I haven't studied your code in detail (I won't be qualified to judge it) but I notice this comment:

  /* Hit the faster unicode_concatenate method if and only if
     all the following conditions are true:
     1. The left operand is a unicode type
     2. The right operand is a unicode type
     3. The left operand's __add__ method isn't overriden */


I don't think that's sufficient. You also need to check the right operand's __radd__ method if it is a subclass of the left:

class A(str):
    pass

class B(str):
    def __radd__(self, other):
        return B(other.uppper() + str(self))

a = A("hello ")
b = B("world")
assert a + b == "HELLO world"



Also you have some tests, but I don't think they're sufficient. You have a comment about "Longer strings to prevent interning" but I'm not sure that a mere 21 characters is guaranteed now and forever to do that. I'd be much happier to see a long string which is not an identifier:

s = S("# ! ~"*50)  # hopefully will not be interned

plus an assertion to check that it is not interned. That way, if the rules for interning ever change, the test will fail loudly and clearly rather than silently do the wrong thing.

(Better still would be an actual language API for un-interning strings, if one exists.)

Also, I see that you have tests to check that the optimized path is taken for subclasses, but do you have tests to check that it is NOT taken when it shouldn't be?
History
Date User Action Args
2016-07-06 01:34:54steven.dapranosetrecipients: + steven.daprano, lemburg, pitrou, vstinner, benjamin.peterson, ezio.melotti, ammar2
2016-07-06 01:34:53steven.dapranosetmessageid: <1467768893.88.0.743546082022.issue27458@psf.upfronthosting.co.za>
2016-07-06 01:34:53steven.dapranolinkissue27458 messages
2016-07-06 01:34:51steven.dapranocreate