Skip to content

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

Merged
merged 1 commit into from
Apr 1, 2014
Merged

Conversation

dhylands
Copy link
Contributor

@dhylands dhylands commented Apr 1, 2014

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

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
Copy link
Contributor

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

Copy link
Contributor Author

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

@dpgeorge
Copy link
Member

dpgeorge commented Apr 1, 2014

Great work. When we have proper file headers, please remember to attribute this work to yourself.

dpgeorge added a commit that referenced this pull request Apr 1, 2014
@dpgeorge dpgeorge merged commit 46330bd into micropython:master Apr 1, 2014
@dpgeorge
Copy link
Member

dpgeorge commented Apr 1, 2014

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@dhylands
Copy link
Contributor Author

dhylands commented Apr 1, 2014

Great work. When we have proper file headers, please remember to attribute this work to yourself.

git blame tells the story... :)

@dhylands
Copy link
Contributor Author

dhylands commented Apr 1, 2014

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.

Sounds good - I'll do that.

@dhylands dhylands deleted the str-format branch November 8, 2015 02:40
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Nov 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy