-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Enhance str.format support #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This adds support for almost everything (the comma isn't currently supported). The "unspecified" type with floats also doesn't behave exactly like python. Tested under unix with float and double Spot tested on stmhal
@@ -198,6 +198,10 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) { | |||
return MP_OBJ_SMALL_INT_VALUE(arg); | |||
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) { | |||
return mp_obj_int_get_checked(arg); | |||
#if MICROPY_ENABLE_FLOAT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet was already there, was already discussed, and removed. Python is no flaky php and doesn't allow make glorious errors by using incorrect types for operations. E.g.:
>>> a=[1,2,4,4]
>>> a[1.0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not float
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh.
Ok - I'll fix that up
Great work. When we have proper file headers, please remember to attribute this work to yourself. |
Hmm, the test script is rather slow to run. 5.8s for uPy, and 6.5s for CPython, with 600 thousand output lines. Can we have a cut down version to run by default, and a full version to run optionally? I run the tests quite often, so like them to be quick. |
@@ -492,28 +493,389 @@ STATIC mp_obj_t str_strip(uint n_args, const mp_obj_t *args) { | |||
return mp_obj_new_str(orig_str + first_good_char_pos, stripped_len, false); | |||
} | |||
|
|||
// Takes an int arg, but only parses unsigned numbers, and only changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually would be nice to put these into some helper file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - I looked at how it was done in printf, and strtol/strtoul also wasn't quite what I wanted either, which is why I wrote yet another variant.
git blame tells the story... :) |
Sounds good - I'll do that. |
This adds support for almost everything (the comma isn't currently
supported).
The "unspecified" type with floats also doesn't behave exactly like
python.
Tested under unix with float and double
Spot tested on stmhal