diff options
author | Dave Hylands <dhylands@gmail.com> | 2014-04-02 12:07:31 -0700 |
---|---|---|
committer | Dave Hylands <dhylands@gmail.com> | 2014-04-02 12:10:18 -0700 |
commit | 22fe4d7344674d3604bd9016115503bcc8822fc8 (patch) | |
tree | aa09e2375a11fe09a77a2087ce22a7a5df173555 /py | |
parent | ad1bac63f714550bc6e2b0a718ee155288254b7a (diff) | |
download | micropython-22fe4d7344674d3604bd9016115503bcc8822fc8.tar.gz micropython-22fe4d7344674d3604bd9016115503bcc8822fc8.zip |
Fix str.format to work with {:f/g/e} and ints
Also fix objstr.c to compile when floats disabled.
Diffstat (limited to 'py')
-rw-r--r-- | py/objstr.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/py/objstr.c b/py/objstr.c index f22c6b1bae..d0dee04e52 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -788,9 +788,11 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Unknown format code '%c' for object of type '%s'", type, mp_obj_get_type_str(arg))); } - + } + // NOTE: no else here. We need the e, f, g etc formats for integer + // arguments (from above if) to take this if. #if MICROPY_ENABLE_FLOAT - } else if (arg_looks_numeric(arg)) { + if (arg_looks_numeric(arg)) { if (!type) { // Even though the docs say that an unspecified type is the same @@ -847,9 +849,10 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { "Unknown format code '%c' for object of type 'float'", type, mp_obj_get_type_str(arg))); } + } else #endif - } else { + { // arg doesn't look like a number if (align == '=') { |