From 9a208a6950900fa3184ef381e84d4d675c68cc97 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 1 Sep 2024 23:16:06 +0800 Subject: [PATCH] fix[tool]: keep `experimentalCodegen` blank in standard json input (#4216) in standard json input, `experimentalCodegen` would default to true, creating a conflict if the user used `#pragma experimental-codegen`. set it to `None`. misc/refactor: - refactor `get_settings` function. --------- Co-authored-by: Ramana Kumar --- .../unit/cli/vyper_json/test_get_settings.py | 13 +++++++++++- vyper/cli/vyper_json.py | 20 +++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/unit/cli/vyper_json/test_get_settings.py b/tests/unit/cli/vyper_json/test_get_settings.py index 540a26f062..077f424d45 100644 --- a/tests/unit/cli/vyper_json/test_get_settings.py +++ b/tests/unit/cli/vyper_json/test_get_settings.py @@ -1,6 +1,6 @@ import pytest -from vyper.cli.vyper_json import get_evm_version +from vyper.cli.vyper_json import get_evm_version, get_settings from vyper.exceptions import JSONError @@ -30,3 +30,14 @@ def test_early_evm(evm_version_str): @pytest.mark.parametrize("evm_version_str", ["london", "paris", "shanghai", "cancun"]) def test_valid_evm(evm_version_str): assert evm_version_str == get_evm_version({"settings": {"evmVersion": evm_version_str}}) + + +def test_experimental_codegen_settings(): + input_json = {"settings": {}} + assert get_settings(input_json).experimental_codegen is None + + input_json = {"settings": {"experimentalCodegen": True}} + assert get_settings(input_json).experimental_codegen is True + + input_json = {"settings": {"experimentalCodegen": False}} + assert get_settings(input_json).experimental_codegen is False diff --git a/vyper/cli/vyper_json.py b/vyper/cli/vyper_json.py index beab06e3df..7d0e6064af 100755 --- a/vyper/cli/vyper_json.py +++ b/vyper/cli/vyper_json.py @@ -249,16 +249,11 @@ def get_search_paths(input_dict: dict) -> list[PurePath]: return [PurePath(p) for p in ret] -def compile_from_input_dict( - input_dict: dict, exc_handler: Callable = exc_handler_raises -) -> tuple[dict, dict]: - if input_dict["language"] != "Vyper": - raise JSONError(f"Invalid language '{input_dict['language']}' - Only Vyper is supported.") - +def get_settings(input_dict: dict) -> Settings: evm_version = get_evm_version(input_dict) optimize = input_dict["settings"].get("optimize") - experimental_codegen = input_dict["settings"].get("experimentalCodegen", False) + experimental_codegen = input_dict["settings"].get("experimentalCodegen") if isinstance(optimize, bool): # bool optimization level for backwards compatibility warnings.warn( @@ -271,10 +266,19 @@ def compile_from_input_dict( else: assert optimize is None - settings = Settings( + return Settings( evm_version=evm_version, optimize=optimize, experimental_codegen=experimental_codegen ) + +def compile_from_input_dict( + input_dict: dict, exc_handler: Callable = exc_handler_raises +) -> tuple[dict, dict]: + if input_dict["language"] != "Vyper": + raise JSONError(f"Invalid language '{input_dict['language']}' - Only Vyper is supported.") + + settings = get_settings(input_dict) + no_bytecode_metadata = not input_dict["settings"].get("bytecodeMetadata", True) integrity = input_dict.get("integrity")