Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What should you use instead if you want the original functionality?



If I'm understanding this correctly: the only way to convert an extremely large base10 string to an integer using the standard library is to muck with global interpreter settings?

It seems short sighted to not provide some function that mimics legacy functionality exactly. Even if it is something like int.parse_string_unlimited(). Especially since a random library can just set the cap to 0 and side-step the problem entirely.


> Especially since a random library can just set the cap to 0 and side-step the problem entirely.

Until another random library sets it to its preferred value (see https://news.ycombinator.com/item?id=32738206 for a similar issue with a CPU flag for supporting IEEE subnormals)

We might end up with libraries that keep setting that global to the value they need on every call into them.


Oh fun. Just what Python needs more of, this...

    try:
        value = int(value_to_parse)
    except ValueError:
        import sys
        __old_int_max_str_digits = sys.get_int_max_str_digits()
        sys.set_int_max_str_digits(0)
        value = int(value_to_parse)
        sys.set_int_max_str_digits(__old_int_max_str_digits)
Or maybe just this:

    class UnboundedIntParsing:
        def __enter__(self):
            self.__old_int_max_str_digits = sys.get_int_max_str_digits()
            return self
    
        def __exit__(self, *args):
            sys.set_int_max_str_digits(self.__old_int_max_str_digits)

    with UnboundedIntParsing as uip:
        value = int(str_value)


Needs to be made thread safe!


Yeah, I like the context manager version of this. That way it's maintainable!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: