Skip to content

Commit

Permalink
Change use of getcontext() to fresh Context()
Browse files Browse the repository at this point in the history
vyperlang/vyper#2479 disabled changes to the
global decimal context to preserve compile-time constant semantics.
This commit changes use of the global getcontext to a local context. It
shouldn't change the behavior of the current code (since it didn't depend
on modifying the global context, just having a local Context with the
correct precision).
  • Loading branch information
charles-cooper committed Oct 24, 2021
1 parent 6d953c1 commit be67fb9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions brownie/convert/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

from copy import deepcopy
from decimal import Decimal, getcontext
from decimal import Decimal, Context
from typing import Any, Dict, ItemsView, KeysView, List, Optional, Sequence, TypeVar, Union

import eth_utils
Expand Down Expand Up @@ -182,11 +182,11 @@ def _to_fixed(value: Any) -> Decimal:
except TypeError:
pass
try:
ctx = getcontext()
ctx = Context()
ctx.prec = 100
return Decimal(value, context=ctx)
except Exception:
raise TypeError(f"Cannot convert {type(value).__name__} '{value}' to decimal.")
except Exception as e:
raise TypeError(f"Cannot convert {type(value).__name__} '{value}' to decimal.") from e


class EthAddress(str):
Expand Down

0 comments on commit be67fb9

Please sign in to comment.