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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
437a90b4
Commit
437a90b4
authored
Sep 13, 2015
by
Jelle Zijlstra
Committed by
Jelle Zijlstra
Mar 20, 2016
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
Changes
1
Show 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,18 +2886,23 @@ class JoinedStrNode(ExprNode):
self
.
values
=
[
v
.
analyse_types
(
env
)
for
v
in
self
.
values
]
self
.
values
=
[
v
.
coerce_to_pyobject
(
env
)
for
v
in
self
.
values
]
self
.
is_temp
=
1
# TODO make this actually work
return
self
.
values
[
1
]
if
len
(
self
.
values
)
>
1
else
self
.
values
[
0
]
return
self
def
generate_result_code
(
self
,
code
):
# TODO this just returns the first value
code
.
putln
(
'%s = %s;'
%
(
self
.
result
(),
self
.
values
[
0
].
py_result
()))
# TODO this just returns the first value and the refnanny doesn't like it
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
):
# {}-delimited portions of an f-string
#
# 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__
subexprs
=
[
'value'
,
'format_spec'
]
...
...
@@ -2916,13 +2921,34 @@ class FormattedValueNode(ExprNode):
value_result
=
self
.
value
.
py_result
()
format_spec_result
=
self
.
format_spec
.
py_result
()
# 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
code
.
putln
(
"%s = PyObject_Format(%s, %s); %s"
%
(
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 %s"
%
(
self
.
result
(),
value_result
,
format_spec_result
,
decref_line
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
result
())
code
.
put_gotref
(
self
.
py_
result
())
#-------------------------------------------------------------------
...
...
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