def test_add_doc(): def f(): """Icky doc""" pass six._add_doc(f, """New doc""") assert f.__doc__ == "New doc"
func.__doc__ = doc # xb and xu are different from b and u in six. # Code without 2.5 support does not need xb(). # Code that only supports Python 3 versions greater than 3.3 thus does not need xu(). if not PY2: def xb(string): return string.encode('utf-8') def xu(string): return string else: def xb(string): return string.encode('utf-8') if isinstance(string, unicode) else string def xu(string): return string if isinstance(string, unicode) else unicode(string, 'utf-8') _add_doc(xb, '''Byte literal''') _add_doc(xu, '''Text literal''') try: _bytearray = bytearray # New in version 2.6. except NameError: _bytearray = type(None) try: _memoryview = memoryview # New in version 2.7. except NameError: _memoryview = type(None) def force_bytes(value, encoding='utf-8', errors='strict'): '''Force value to bytes.'''