Commit 47d84dd3 authored by Stefan Behnel's avatar Stefan Behnel

we actually know that FormattedValueNode always returns a Unicode string and...

we actually know that FormattedValueNode always returns a Unicode string and no other object type => set node type accordingly
parent febba4ef
...@@ -3014,17 +3014,17 @@ class FormattedValueNode(ExprNode): ...@@ -3014,17 +3014,17 @@ class FormattedValueNode(ExprNode):
# format_spec JoinedStrNode or None Format string passed to __format__ # format_spec JoinedStrNode or None Format string passed to __format__
subexprs = ['value', 'format_spec'] subexprs = ['value', 'format_spec']
type = py_object_type type = unicode_type
is_temp = True is_temp = True
find_conversion_func = { find_conversion_func = {
's': 'PyObject_Str', 's': 'PyObject_Str',
'r': 'PyObject_Repr', 'r': 'PyObject_Repr',
'a': 'PyObject_ASCII', # NOTE: Py3-only! 'a': 'PyObject_ASCII', # NOTE: mapped to PyObject_Repr() in Py2
}.get }.get
def may_be_none(self): def may_be_none(self):
# PyObject_Format() always returns a string (str in Py3, str/unicode in Py2) or raises an exception # PyObject_Format() always returns a Unicode string or raises an exception
return False return False
def analyse_types(self, env): def analyse_types(self, env):
...@@ -3041,6 +3041,7 @@ class FormattedValueNode(ExprNode): ...@@ -3041,6 +3041,7 @@ class FormattedValueNode(ExprNode):
else: else:
# common case: expect simple Unicode pass-through if no format spec # common case: expect simple Unicode pass-through if no format spec
format_func = '__Pyx_PyObject_FormatSimple' format_func = '__Pyx_PyObject_FormatSimple'
# passing a Unicode format string in Py2 forces PyObject_Format() to also return a Unicode string
format_spec = Naming.empty_unicode format_spec = Naming.empty_unicode
if self.conversion_char: if self.conversion_char:
......
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