Commit f3a876ff authored by Stefan Behnel's avatar Stefan Behnel

implement somewhat useless but obvious and straight forward string conversion...

implement somewhat useless but obvious and straight forward string conversion of the C error return type
parent ea17ab16
...@@ -1758,9 +1758,13 @@ class CReturnCodeType(CIntType): ...@@ -1758,9 +1758,13 @@ class CReturnCodeType(CIntType):
is_returncode = True is_returncode = True
exception_check = False exception_check = False
default_format_spec = ''
def can_coerce_to_pystring(self, env, format_spec=None): def can_coerce_to_pystring(self, env, format_spec=None):
return False return not format_spec
def convert_to_pystring(self, cvalue, code, format_spec=None):
return "__Pyx_NewRef(%s)" % code.globalstate.get_py_string_const(StringEncoding.EncodedString("None")).cname
class CBIntType(CIntType): class CBIntType(CIntType):
......
...@@ -103,13 +103,15 @@ def format_bool(bint x): ...@@ -103,13 +103,15 @@ def format_bool(bint x):
def format_c_values(Py_UCS4 uchar, Py_UNICODE pyunicode): def format_c_values(Py_UCS4 uchar, Py_UNICODE pyunicode):
""" """
>>> s, s1, s2 = format_c_values(b'A'.decode('ascii'), b'X'.decode('ascii')) >>> s, s1, s2, s3 = format_c_values(b'A'.decode('ascii'), b'X'.decode('ascii'))
>>> print(s) >>> print(s)
AXAX AXAX
>>> print(s1) >>> print(s1)
A A
>>> print(s2) >>> print(s2)
X X
>>> print(s3)
None
""" """
s = f"{uchar}{pyunicode}{uchar!s}{pyunicode!s}" s = f"{uchar}{pyunicode}{uchar!s}{pyunicode!s}"
...@@ -118,7 +120,11 @@ def format_c_values(Py_UCS4 uchar, Py_UNICODE pyunicode): ...@@ -118,7 +120,11 @@ def format_c_values(Py_UCS4 uchar, Py_UNICODE pyunicode):
assert isinstance(s1, unicode), type(s1) assert isinstance(s1, unicode), type(s1)
s2 = f"{pyunicode}" s2 = f"{pyunicode}"
assert isinstance(s2, unicode), type(s2) assert isinstance(s2, unicode), type(s2)
return s, s1, s2 l = [1, 2, 3]
s3 = f"{l.reverse()}" # C int return value => None
assert isinstance(s3, unicode), type(s3)
assert l == [3, 2, 1]
return s, s1, s2, s3
def format_strings(str s, unicode u): def format_strings(str s, unicode u):
......
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