Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
437a90b4
Commit
437a90b4
authored
9 years ago
by
Jelle Zijlstra
Committed by
Jelle Zijlstra
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fstrings: make conversion chars work
Still doesn't do concatenation of FormattedValueNodes correctly.
parent
04bfbb49
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
7 deletions
+33
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+33
-7
No files found.
Cython/Compiler/ExprNodes.py
View file @
437a90b4
...
@@ -2886,19 +2886,24 @@ class JoinedStrNode(ExprNode):
...
@@ -2886,19 +2886,24 @@ class JoinedStrNode(ExprNode):
self
.
values
=
[
v
.
analyse_types
(
env
)
for
v
in
self
.
values
]
self
.
values
=
[
v
.
analyse_types
(
env
)
for
v
in
self
.
values
]
self
.
values
=
[
v
.
coerce_to_pyobject
(
env
)
for
v
in
self
.
values
]
self
.
values
=
[
v
.
coerce_to_pyobject
(
env
)
for
v
in
self
.
values
]
self
.
is_temp
=
1
self
.
is_temp
=
1
# TODO make this actually work
return
self
.
values
[
1
]
if
len
(
self
.
values
)
>
1
else
self
.
values
[
0
]
return
self
return
self
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
# TODO this just returns the first value
# TODO this just returns the first value and the refnanny doesn't like it
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
self
.
values
[
0
].
py_result
()))
val
=
self
.
values
[
1
]
if
len
(
self
.
values
)
>
1
else
self
.
values
[
0
]
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
val
.
py_result
()))
code
.
putln
(
'__Pyx_INCREF(%s);'
%
self
.
result
())
code
.
put_gotref
(
self
.
py_result
())
class
FormattedValueNode
(
ExprNode
):
class
FormattedValueNode
(
ExprNode
):
# {}-delimited portions of an f-string
# {}-delimited portions of an f-string
#
#
# value ExprNode The expression itself
# value
ExprNode The expression itself
# conversion
str or None Type conversion (!s, !r, !a, or none)
# conversion
_char
str or None Type conversion (!s, !r, !a, or none)
# 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'
]
conversion_chars
=
'sra'
conversion_chars
=
'sra'
...
@@ -2916,13 +2921,34 @@ class FormattedValueNode(ExprNode):
...
@@ -2916,13 +2921,34 @@ class FormattedValueNode(ExprNode):
value_result
=
self
.
value
.
py_result
()
value_result
=
self
.
value
.
py_result
()
format_spec_result
=
self
.
format_spec
.
py_result
()
format_spec_result
=
self
.
format_spec
.
py_result
()
# TODO conversion chars
# TODO conversion chars
if
self
.
conversion_char
==
's'
:
fn
=
'PyObject_Str'
elif
self
.
conversion_char
==
'r'
:
fn
=
'PyObject_Repr'
elif
self
.
conversion_char
==
'a'
:
fn
=
'PyObject_ASCII'
else
:
fn
=
None
if
fn
is
not
None
:
code
.
putln
(
'%s = %s(%s); %s'
%
(
value_result
,
fn
,
value_result
,
code
.
error_goto_if_null
(
value_result
,
self
.
pos
)
))
code
.
put_gotref
(
value_result
)
decref_line
=
'__Pyx_DECREF(%s);'
%
value_result
else
:
decref_line
=
''
code
.
putln
(
"%s = PyObject_Format(%s, %s); %s"
%
(
code
.
putln
(
"%s = PyObject_Format(%s, %s); %s
%s
"
%
(
self
.
result
(),
self
.
result
(),
value_result
,
value_result
,
format_spec_result
,
format_spec_result
,
decref_line
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
result
())
code
.
put_gotref
(
self
.
py_
result
())
#-------------------------------------------------------------------
#-------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment