[issue9574] complex does not parse strings containing decimals

Mark Dickinson report at bugs.python.org
Sat Aug 28 19:54:51 CEST 2010

Mark Dickinson <dickinsm at gmail.com> added the comment:

If someone does want to produce a patch, here's the grammar that I suggest, in pseudo BNF form.  This would be reasonably simple to implement, and is also simple to describe.

whitespace = ' ' | '\t' | '\n' | '\v' | '\f'    # include other non-ASCII whitespace?
binop = [whitespace] ('+' | '-') [whitespace]
imag_marker = 'j' | 'J'
complex_string = float_string binop float_string imag_marker
               | float_string imag_marker
               | float_string
padded_complex_string = [whitespace] complex_string [whitespace]
complex_constructor_input = padded_complex_string
                          | [whitespace] '(' padded_complex_string ')' [whitespace]

where float_string is any string that (a) doesn't contain leading or trailing whitespace, and (b) is accepted by the current float constructor.

This would allow (a) and (f) in the previous message, but not (b) or (c).


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list