Commit b7cda092 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_str: Make bytes(bstr) -> bstr, unicode(ustr) -> ustr

In other words casting to bytes/unicode preserves pygolang string to
remain pygolang string.

Without the changes to bstr/ustr added test fails as e.g.

    >       assert bytes  (bs) is bs
    E       AssertionError: assert b'\xd0\xbc\xd0\xb8\xd1\x80' is b'\xd0\xbc\xd0\xb8\xd1\x80'
    E        +  where b'\xd0\xbc\xd0\xb8\xd1\x80' = bytes(b'\xd0\xbc\xd0\xb8\xd1\x80')

in other words bytes(bstr) was creating a copy and changing type to bytes.
parent 85c4615d
......@@ -120,7 +120,7 @@ class pybstr(bytes):
__slots__ = ()
# __bytes__ - no need
def __bytes__(self): return self
def __unicode__(self): return pyu(self)
def __str__(self):
......@@ -138,7 +138,7 @@ cdef class pyustr(unicode):
"""
def __bytes__(self): return pyb(self)
# __unicode__ - no need
def __unicode__(self): return self
def __str__(self):
if PY_MAJOR_VERSION >= 3:
......
......@@ -142,6 +142,10 @@ def test_strings_basic():
assert b(bs) is bs
assert u(us) is us
# bytes(b(·)) = identity, unicode(u(·)) = identity
assert bytes (bs) is bs
assert unicode(us) is us
# unicode(b) -> u, bytes(u) -> b
_ = unicode(bs); assert type(_) is ustr
_ = bytes (us); assert type(_) is bstr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment