Skip to content
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

Change use of getcontext() to fresh Context() #1310

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions brownie/convert/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from decimal import Decimal, getcontext
from typing import Any, Dict, ItemsView, KeysView, List, Optional, Sequence, TypeVar, Union

try:
from vyper.exceptions import DecimalOverrideException
except ImportError:
DecimalOverrideException = BaseException # regular catch blocks shouldn't catch

import eth_utils
from hexbytes import HexBytes

Expand Down Expand Up @@ -182,11 +187,15 @@ def _to_fixed(value: Any) -> Decimal:
except TypeError:
pass
try:
ctx = getcontext()
ctx.prec = 100
return Decimal(value, context=ctx)
except Exception:
raise TypeError(f"Cannot convert {type(value).__name__} '{value}' to decimal.")
try:
# until vyper v0.3.1 we can mess with the precision
ctx = getcontext()
ctx.prec = 78
except DecimalOverrideException:
pass # vyper set the precision, do nothing.
return Decimal(value)
except Exception as e:
raise TypeError(f"Cannot convert {type(value).__name__} '{value}' to decimal.") from e


class EthAddress(str):
Expand Down