Commit 77b74cde authored by Stefan Behnel's avatar Stefan Behnel

Merge branch '0.29.x'

parents 2f86bc45 dcf6b827
......@@ -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)
......
......@@ -4348,7 +4348,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
_parse_string_format_regex = (
u'(%(?:' # %...
u'(?:[0-9]+|[ ])?' # width (optional) or space prefix fill character (optional)
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)
)
......@@ -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,
......
......@@ -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-13-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-11 -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-13-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-11 -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,
)
......
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