4 ms·
https://docs.python.org/3/library/stdtypes.html#configuring-the-limit https://docs.python.org/3/library/stdtypes.html#configuring-...
by Veedrac 4y ago
https://docs.python.org/3/library/stdtypes.html#configuring-the-limit https://docs.python.org/3/library/stdtypes.html#configuring-...
- mywittyname 4y agoIf 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.
- Someone 4y ago> 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 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.
- mywittyname 4y agoOh 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)
- dmurray 4y agoNeeds to be made thread safe!
- sidewndr46 4y agoYeah, I like the context manager version of this. That way it's maintainable!