diff --git a/bin/vyper b/bin/vyper index d2e470bb943..15ad6aa49d3 100755 --- a/bin/vyper +++ b/bin/vyper @@ -158,7 +158,6 @@ if __name__ == '__main__': out = vyper.compile_codes( codes, ['bytecode', 'bytecode_runtime', 'abi', 'source_map', 'method_identifiers'], - output_type='dict', exc_handler=exc_handler, interface_codes=get_interface_codes(codes) ) @@ -177,13 +176,12 @@ if __name__ == '__main__': for f in orig_args: formats.append(translate_map.get(f, f)) - out_list = vyper.compile_codes( + out_list = list(vyper.compile_codes( codes, formats, - output_type='list', exc_handler=exc_handler, interface_codes=get_interface_codes(codes) - ) + ).values()) for out in out_list: for f in orig_args: diff --git a/bin/vyper-serve b/bin/vyper-serve index c89968bcc54..0d7b1f4871a 100755 --- a/bin/vyper-serve +++ b/bin/vyper-serve @@ -92,7 +92,6 @@ class VyperRequestHandler(BaseHTTPRequestHandler): out_dict = vyper.compile_codes( {'': code}, vyper.compiler.output_formats_map.keys(), - output_type='dict', )[''] out_dict['ir'] = str(out_dict['ir']) except ParserException as e: diff --git a/tests/compiler/test_bytecode_runtime.py b/tests/compiler/test_bytecode_runtime.py index b9754d2f6de..90e603b9ff4 100644 --- a/tests/compiler/test_bytecode_runtime.py +++ b/tests/compiler/test_bytecode_runtime.py @@ -8,7 +8,7 @@ def a() -> bool: return True """ - out = vyper.compile_codes({'': code}, ['bytecode_runtime', 'bytecode'])[0] + out = vyper.compile_code(code, ['bytecode_runtime', 'bytecode']) assert len(out['bytecode']) > len(out['bytecode_runtime']) assert out['bytecode_runtime'][2:] in out['bytecode'][2:] diff --git a/tests/compiler/test_opcodes.py b/tests/compiler/test_opcodes.py index c9fcf427e01..5248718dd78 100644 --- a/tests/compiler/test_opcodes.py +++ b/tests/compiler/test_opcodes.py @@ -8,7 +8,7 @@ def a() -> bool: return True """ - out = vyper.compile_codes({'': code}, ['opcodes_runtime', 'opcodes'])[0] + out = vyper.compile_code(code, ['opcodes_runtime', 'opcodes']) assert len(out['opcodes']) > len(out['opcodes_runtime']) assert out['opcodes_runtime'] in out['opcodes'] diff --git a/tests/parser/functions/test_abi.py b/tests/parser/functions/test_abi.py index b97a478abd1..22a59af2cfd 100644 --- a/tests/parser/functions/test_abi.py +++ b/tests/parser/functions/test_abi.py @@ -1,5 +1,5 @@ from vyper.compiler import ( - compile_codes, + compile_code, mk_full_signature, ) @@ -56,11 +56,10 @@ def foo(x: uint256) -> bytes[100]: return b"hello" """ - out = compile_codes( - codes={'t.vy': code}, + out = compile_code( + code, output_formats=['method_identifiers'], - output_type='list' - )[0] + ) assert out['method_identifiers'] == { 'foo(uint256)': '0x2fbebd38', diff --git a/tests/parser/functions/test_interfaces.py b/tests/parser/functions/test_interfaces.py index 80177bb5655..75010a777d4 100644 --- a/tests/parser/functions/test_interfaces.py +++ b/tests/parser/functions/test_interfaces.py @@ -60,7 +60,7 @@ def allowance(_owner: address, _spender: address) -> (uint256, uint256): constan def test(_owner: address): modifying """ - out = compile_codes({'one.vy': code}, ['external_interface'])[0] + out = compile_codes({'one.vy': code}, ['external_interface'])['one.vy'] out = out['external_interface'] assert interface.strip() == out.strip() @@ -79,7 +79,7 @@ def test() -> bool: """ assert_compile_failed( - lambda: compile_codes({'one.vy': code}), + lambda: compile_code(code), StructureException ) @@ -121,7 +121,7 @@ def bar() -> uint256: return 2 """ - assert compile_codes({'one.vy': code}, interface_codes=interface_codes)[0] + assert compile_code(code, interface_codes=interface_codes) not_implemented_code = """ import a as FooBarInterface @@ -135,7 +135,7 @@ def foo() -> uint256: """ assert_compile_failed( - lambda: compile_codes({'one.vy': not_implemented_code}, interface_codes=interface_codes)[0], + lambda: compile_code(not_implemented_code, interface_codes=interface_codes), StructureException ) diff --git a/vyper/compiler.py b/vyper/compiler.py index 5adb7bd07f2..0ce1043dd24 100644 --- a/vyper/compiler.py +++ b/vyper/compiler.py @@ -215,7 +215,6 @@ def _mk_ast_dict(code, contract_name, interface_codes): def compile_codes(codes, output_formats=None, - output_type='list', exc_handler=None, interface_codes=None): if output_formats is None: @@ -240,14 +239,17 @@ def compile_codes(codes, else: raise exc - if output_type == 'list': - return list(out.values()) - elif output_type == 'dict': - return out - else: - raise ValueError(f'Unsupported output type {repr(output_type)}') + return out + + +UNKNOWN_CONTRACT_NAME = '' def compile_code(code, output_formats=None, interface_codes=None): - codes = {'': code} - return compile_codes(codes, output_formats, 'list', interface_codes=interface_codes)[0] + codes = {UNKNOWN_CONTRACT_NAME: code} + + return compile_codes( + codes, + output_formats, + interface_codes=interface_codes, + )[UNKNOWN_CONTRACT_NAME]