Closed CogniacViSean closed 3 years ago
test case to reproduce:
# -*- coding: utf-8 -*-
import sys
class Test(object):
def __repr__(self):
s = "%s" % u"сок"
return s.encode(sys.stdout.encoding)
def __str__(self):
s = "%s" % u"сок"
return s.encode(sys.stdout.encoding)
x = Test()
print(x)
python2 runs ok, python3 returns TypeError: __str__ returned non-string (type bytes)
This six library has a utility decorator that can handle this, worth adding to the project? It may have other tools for python2/3 compatibility that may be useful elsewhere:
six is currently the # 2 pypi package so it seems like an okay dependency to introduce
Found this because calling CogniacConnection.get_all_subjects() causes:
TypeError: __repr__ returned non-string (type bytes)
I believe it's these lines, the Application object doesn't have this problem, and returns the string directly: https://github.com/Cogniac/cogniac-sdk-py/blob/11f985a07bbaf5616315abbb0a56c75bc7928472/cogniac/subject.py#L216 https://github.com/Cogniac/cogniac-sdk-py/blob/11f985a07bbaf5616315abbb0a56c75bc7928472/cogniac/subject.py#L220
Perhaps related to Python 2 to 3 compatibility?