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
77b74cde
Commit
77b74cde
authored
May 09, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '0.29.x'
parents
2f86bc45
dcf6b827
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
14 deletions
+26
-14
CHANGES.rst
CHANGES.rst
+6
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+10
-4
tests/run/fstring.pyx
tests/run/fstring.pyx
+10
-10
No files found.
CHANGES.rst
View file @
77b74cde
...
...
@@ -414,6 +414,12 @@ Bugs fixed
* Complex buffer item types of structs of arrays could fail to validate.
Patch by Leo and smutch. (Github issue #1407)
* Optimised ``%d`` string formatting into f-strings failed on float values.
(Github issue #3092)
* Optimised aligned string formatting (``%05s``, ``%-5s``) failed.
(Github issue #3476)
* When importing the old Cython ``build_ext`` integration with distutils, the
additional command line arguments leaked into the regular command.
Patch by Kamekameha. (Github issue #2209)
...
...
Cython/Compiler/Optimize.py
View file @
77b74cde
...
...
@@ -4347,10 +4347,10 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
return
self
.
visit_BinopNode
(
node
)
_parse_string_format_regex
=
(
u'(%(?:'
# %...
u'(?:[
0-9]+|[ ])?'
# width (optional) or space prefix fill character (optional)
u'(?:[.][0-9]+)?'
# precision (optional)
u')?.)'
# format type (or something different for unsupported formats)
u'(%(?:'
# %...
u'(?:[
-0-9]+|[ ])?'
# width (optional) or space prefix fill character (optional)
u'(?:[.][0-9]+)?'
# precision (optional)
u')?.)'
# format type (or something different for unsupported formats)
)
def
_build_fstring
(
self
,
pos
,
ustring
,
format_args
):
...
...
@@ -4389,9 +4389,15 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
elif
format_type
in
u'ars'
:
format_spec
=
format_spec
[:
-
1
]
conversion_char
=
format_type
if
format_spec
.
startswith
(
'0'
):
format_spec
=
'>'
+
format_spec
[
1
:]
# right-alignment '%05s' spells '{:>5}'
elif
format_type
==
u'd'
:
# '%d' formatting supports float, but '{obj:d}' does not => convert to int first.
conversion_char
=
'd'
if
format_spec
.
startswith
(
'-'
):
format_spec
=
'<'
+
format_spec
[
1
:]
# left-alignment '%-5s' spells '{:<5}'
substrings
.
append
(
ExprNodes
.
FormattedValueNode
(
arg
.
pos
,
value
=
arg
,
conversion_char
=
conversion_char
,
...
...
tests/run/fstring.pyx
View file @
77b74cde
...
...
@@ -537,29 +537,29 @@ def generated_fstring(int i, float f, unicode u not None, o):
"""
>>> i, f, u, o = 11, 1.3125, u'xyz', [1]
>>> print(((
... u"(i) %s-%.3s-%r-%.3r-%d-%3d-%o-%04o-%x-%4x-%X-%03X-%.1f-%04.2f %% "
... u"(u) %s-%.2s-%r-%.7r %% "
... u"(i) %s-%.3s-%r-%.3r-%d-%3d-%
-3d-%
o-%04o-%x-%4x-%X-%03X-%.1f-%04.2f %% "
... u"(u) %s-%.2s-%r-%.7r
-%05s-%-5s
%% "
... u"(o) %s-%.2s-%r-%.2r %% "
... u"(f) %.2f-%d"
... ) % (
... i, i, i, i, i, i, i, i, i, i, i, i, i, i,
... u, u, u, u,
... i, i, i, i, i, i, i, i, i, i, i, i, i, i,
i,
... u, u, u, u,
u, u,
... o, o, o, o,
... f, f,
... )).replace("-u'xyz'", "-'xyz'"))
(i) 11-11-11-11-11- 11-1
3-0013-b- b-B-00B-11.0-11.00 % (u) xyz-xy-'xyz'-'xyz'
% (o) [1]-[1-[1]-[1 % (f) 1.31-1
(i) 11-11-11-11-11- 11-1
1 -13-0013-b- b-B-00B-11.0-11.00 % (u) xyz-xy-'xyz'-'xyz'- xyz-xyz
% (o) [1]-[1-[1]-[1 % (f) 1.31-1
>>> print(generated_fstring(i, f, u, o).replace("-u'xyz'", "-'xyz'"))
(i) 11-11-11-11-11- 11-1
3-0013-b- b-B-00B-11.0-11.00 % (u) xyz-xy-'xyz'-'xyz'
% (o) [1]-[1-[1]-[1 % (f) 1.31-1
(i) 11-11-11-11-11- 11-1
1 -13-0013-b- b-B-00B-11.0-11.00 % (u) xyz-xy-'xyz'-'xyz'- xyz-xyz
% (o) [1]-[1-[1]-[1 % (f) 1.31-1
"""
return
(
u"(i) %s-%.3s-%r-%.3r-%d-%3d-%o-%04o-%x-%4x-%X-%03X-%.1f-%04.2f %% "
u"(u) %s-%.2s-%r-%.7r %% "
u"(i) %s-%.3s-%r-%.3r-%d-%3d-%
-3d-%
o-%04o-%x-%4x-%X-%03X-%.1f-%04.2f %% "
u"(u) %s-%.2s-%r-%.7r
-%05s-%-5s
%% "
u"(o) %s-%.2s-%r-%.2r %% "
u"(f) %.2f-%d"
)
%
(
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
u
,
u
,
u
,
u
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
i
,
u
,
u
,
u
,
u
,
u
,
u
,
o
,
o
,
o
,
o
,
f
,
f
,
)
...
...
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