diff --git a/examples/auctions/blind_auction.vy b/examples/auctions/blind_auction.vy index 966565138f..143206ccb4 100644 --- a/examples/auctions/blind_auction.vy +++ b/examples/auctions/blind_auction.vy @@ -69,10 +69,10 @@ def bid(_blindedBid: bytes32): assert numBids < MAX_BIDS # Add bid to mapping of all bids - self.bids[msg.sender][numBids] = Bid({ - blindedBid: _blindedBid, - deposit: msg.value - }) + self.bids[msg.sender][numBids] = Bid( + blindedBid=_blindedBid, + deposit=msg.value + ) self.bidCounts[msg.sender] += 1 diff --git a/examples/voting/ballot.vy b/examples/voting/ballot.vy index daaf712e0f..9016ae38c6 100644 --- a/examples/voting/ballot.vy +++ b/examples/voting/ballot.vy @@ -57,10 +57,10 @@ def __init__(_proposalNames: bytes32[2]): self.chairperson = msg.sender self.voterCount = 0 for i: int128 in range(2): - self.proposals[i] = Proposal({ - name: _proposalNames[i], - voteCount: 0 - }) + self.proposals[i] = Proposal( + name=_proposalNames[i], + voteCount=0 + ) self.int128Proposals += 1 # Give a `voter` the right to vote on this ballot. diff --git a/tests/functional/builtins/codegen/test_abi.py b/tests/functional/builtins/codegen/test_abi.py index 335f728a37..403ad6fc9a 100644 --- a/tests/functional/builtins/codegen/test_abi.py +++ b/tests/functional/builtins/codegen/test_abi.py @@ -112,8 +112,8 @@ def test_nested_struct(type, abi_type): @external def getStructList() -> {type}: return [ - NestedStruct({{t: MyStruct({{a: msg.sender, b: block.prevhash}}), foo: 1}}), - NestedStruct({{t: MyStruct({{a: msg.sender, b: block.prevhash}}), foo: 2}}) + NestedStruct(t=MyStruct(a=msg.sender, b=block.prevhash), foo=1), + NestedStruct(t=MyStruct(a=msg.sender, b=block.prevhash), foo=2) ] """ diff --git a/tests/functional/builtins/codegen/test_abi_decode.py b/tests/functional/builtins/codegen/test_abi_decode.py index 96cbbe4c2d..dbbf195373 100644 --- a/tests/functional/builtins/codegen/test_abi_decode.py +++ b/tests/functional/builtins/codegen/test_abi_decode.py @@ -35,18 +35,18 @@ def abi_decode(x: Bytes[160]) -> (address, int128, bool, decimal, bytes32): @external def abi_decode_struct(x: Bytes[544]) -> Human: - human: Human = Human({ - name: "", - pet: Animal({ - name: "", - address_: empty(address), - id_: 0, - is_furry: False, - price: 0.0, - data: [0, 0, 0], - metadata: 0x0000000000000000000000000000000000000000000000000000000000000000 - }) - }) + human: Human = Human( + name = "", + pet = Animal( + name = "", + address_ = empty(address), + id_ = 0, + is_furry = False, + price = 0.0, + data = [0, 0, 0], + metadata = 0x0000000000000000000000000000000000000000000000000000000000000000 + ) + ) human = _abi_decode(x, Human) return human """ diff --git a/tests/functional/builtins/codegen/test_abi_encode.py b/tests/functional/builtins/codegen/test_abi_encode.py index 8709e31470..f818b04359 100644 --- a/tests/functional/builtins/codegen/test_abi_encode.py +++ b/tests/functional/builtins/codegen/test_abi_encode.py @@ -34,18 +34,18 @@ def abi_encode( ensure_tuple: bool, include_method_id: bool ) -> Bytes[548]: - human: Human = Human({ - name: name, - pet: Animal({ - name: pet_name, - address_: pet_address, - id_: pet_id, - is_furry: pet_is_furry, - price: pet_price, - data: pet_data, - metadata: pet_metadata - }), - }) + human: Human = Human( + name = name, + pet = Animal( + name = pet_name, + address_ = pet_address, + id_ = pet_id, + is_furry = pet_is_furry, + price = pet_price, + data = pet_data, + metadata = pet_metadata + ), + ) if ensure_tuple: if not include_method_id: return _abi_encode(human) # default ensure_tuple=True @@ -128,7 +128,7 @@ def test_abi_encode_length_failing(get_contract, assert_compile_failed, type, va @internal def foo(): - x: WrappedBytes = WrappedBytes({{bs: {value}}}) + x: WrappedBytes = WrappedBytes(bs={value}) y: {type}[96] = _abi_encode(x, ensure_tuple=True) # should be Bytes[128] """ diff --git a/tests/functional/builtins/codegen/test_empty.py b/tests/functional/builtins/codegen/test_empty.py index 896c845da2..a6c9c6441b 100644 --- a/tests/functional/builtins/codegen/test_empty.py +++ b/tests/functional/builtins/codegen/test_empty.py @@ -351,22 +351,22 @@ def test_empty_struct(get_contract_with_gas_estimation): @external def foo(): - self.foobar = FOOBAR({ - a: 1, - b: 2, - c: True, - d: 3.0, - e: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, - f: msg.sender - }) - bar: FOOBAR = FOOBAR({ - a: 1, - b: 2, - c: True, - d: 3.0, - e: 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, - f: msg.sender - }) + self.foobar = FOOBAR( + a=1, + b=2, + c=True, + d=3.0, + e=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, + f=msg.sender + ) + bar: FOOBAR = FOOBAR( + a=1, + b=2, + c=True, + d=3.0, + e=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, + f=msg.sender + ) self.foobar = empty(FOOBAR) bar = empty(FOOBAR) @@ -575,10 +575,7 @@ def test_map_clear_struct(get_contract_with_gas_estimation): @external def set(): - self.structmap[123] = X({ - a: 333, - b: 444 - }) + self.structmap[123] = X(a=333, b=444) @external def get() -> (int128, int128): diff --git a/tests/functional/codegen/calling_convention/test_default_parameters.py b/tests/functional/codegen/calling_convention/test_default_parameters.py index 4153c7188e..e4db72ab8d 100644 --- a/tests/functional/codegen/calling_convention/test_default_parameters.py +++ b/tests/functional/codegen/calling_convention/test_default_parameters.py @@ -309,7 +309,7 @@ def foo(a: uint256 = 2**8): pass b: uint256 @external -def foo(bar: Bar = Bar({a: msg.sender, b: 1})): pass +def foo(bar: Bar = Bar(a=msg.sender, b=1)): pass """, """ struct Baz: @@ -321,7 +321,7 @@ def foo(bar: Bar = Bar({a: msg.sender, b: 1})): pass b: Baz @external -def foo(bar: Bar = Bar({a: msg.sender, b: Baz({c: block.coinbase, d: -10})})): pass +def foo(bar: Bar = Bar(a=msg.sender, b=Baz(c=block.coinbase, d=-10))): pass """, """ A: public(address) @@ -341,7 +341,7 @@ def foo(a: int112 = min_value(int112)): struct X: x: int128 y: address -BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345}) +BAR: constant(X) = X(x=1, y=0x0000000000000000000000000000000000012345) @external def out_literals(a: int128 = BAR.x + 1) -> X: return BAR @@ -353,8 +353,8 @@ def out_literals(a: int128 = BAR.x + 1) -> X: struct Y: x: X y: uint256 -BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345}) -FOO: constant(Y) = Y({x: BAR, y: 256}) +BAR: constant(X) = X(x=1, y=0x0000000000000000000000000000000000012345) +FOO: constant(Y) = Y(x=BAR, y=256) @external def out_literals(a: int128 = FOO.x.x + 1) -> Y: return FOO @@ -363,7 +363,7 @@ def out_literals(a: int128 = FOO.x.x + 1) -> Y: struct Bar: a: bool -BAR: constant(Bar) = Bar({a: True}) +BAR: constant(Bar) = Bar(a=True) @external def foo(x: bool = True and not BAR.a): @@ -373,7 +373,7 @@ def foo(x: bool = True and not BAR.a): struct Bar: a: uint256 -BAR: constant(Bar) = Bar({ a: 123 }) +BAR: constant(Bar) = Bar(a=123) @external def foo(x: bool = BAR.a + 1 > 456): diff --git a/tests/functional/codegen/calling_convention/test_external_contract_calls.py b/tests/functional/codegen/calling_convention/test_external_contract_calls.py index 8b3f30b5a5..bc9ac94bd5 100644 --- a/tests/functional/codegen/calling_convention/test_external_contract_calls.py +++ b/tests/functional/codegen/calling_convention/test_external_contract_calls.py @@ -1586,7 +1586,7 @@ def test_struct_return_external_contract_call_1(get_contract_with_gas_estimation y: address @external def out_literals() -> X: - return X({x: 1, y: 0x0000000000000000000000000000000000012345}) + return X(x=1, y=0x0000000000000000000000000000000000012345) """ contract_2 = """ @@ -1618,7 +1618,7 @@ def test_struct_return_external_contract_call_2(get_contract_with_gas_estimation z: Bytes[{ln}] @external def get_struct_x() -> X: - return X({{x: {i}, y: "{s}", z: b"{s}"}}) + return X(x={i}, y="{s}", z=b"{s}") """ contract_2 = f""" @@ -1648,7 +1648,7 @@ def test_struct_return_external_contract_call_3(get_contract_with_gas_estimation x: int128 @external def out_literals() -> X: - return X({x: 1}) + return X(x=1) """ contract_2 = """ @@ -1676,7 +1676,7 @@ def test_constant_struct_return_external_contract_call_1(get_contract_with_gas_e x: int128 y: address -BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345}) +BAR: constant(X) = X(x=1, y=0x0000000000000000000000000000000000012345) @external def out_literals() -> X: @@ -1713,7 +1713,7 @@ def test_constant_struct_return_external_contract_call_2( y: String[{ln}] z: Bytes[{ln}] -BAR: constant(X) = X({{x: {i}, y: "{s}", z: b"{s}"}}) +BAR: constant(X) = X(x={i}, y="{s}", z=b"{s}") @external def get_struct_x() -> X: @@ -1746,7 +1746,7 @@ def test_constant_struct_return_external_contract_call_3(get_contract_with_gas_e struct X: x: int128 -BAR: constant(X) = X({x: 1}) +BAR: constant(X) = X(x=1) @external def out_literals() -> X: @@ -1778,7 +1778,7 @@ def test_constant_struct_member_return_external_contract_call_1(get_contract_wit x: int128 y: address -BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345}) +BAR: constant(X) = X(x=1, y=0x0000000000000000000000000000000000012345) @external def get_y() -> address: @@ -1811,7 +1811,7 @@ def test_constant_struct_member_return_external_contract_call_2( y: String[{ln}] z: Bytes[{ln}] -BAR: constant(X) = X({{x: {i}, y: "{s}", z: b"{s}"}}) +BAR: constant(X) = X(x={i}, y="{s}", z=b"{s}") @external def get_y() -> String[{ln}]: @@ -1840,7 +1840,7 @@ def test_constant_struct_member_return_external_contract_call_3(get_contract_wit struct X: x: int128 -BAR: constant(X) = X({x: 1}) +BAR: constant(X) = X(x=1) @external def get_x() -> int128: @@ -1874,7 +1874,7 @@ def test_constant_nested_struct_return_external_contract_call_1(get_contract_wit a: X b: uint256 -BAR: constant(A) = A({a: X({x: 1, y: 0x0000000000000000000000000000000000012345}), b: 777}) +BAR: constant(A) = A(a=X(x=1, y=0x0000000000000000000000000000000000012345), b=777) @external def out_literals() -> A: @@ -1919,7 +1919,7 @@ def test_constant_nested_struct_return_external_contract_call_2( a: X b: uint256 -BAR: constant(A) = A({{a: X({{x: {i}, y: "{s}", z: b"{s}"}}), b: 777}}) +BAR: constant(A) = A(a=X(x={i}, y="{s}", z=b"{s}"), b=777) @external def get_struct_a() -> A: @@ -1966,7 +1966,7 @@ def test_constant_nested_struct_return_external_contract_call_3(get_contract_wit c: A d: bool -BAR: constant(C) = C({c: A({a: X({x: 1, y: -1}), b: 777}), d: True}) +BAR: constant(C) = C(c=A(a=X(x=1, y=-1), b=777), d=True) @external def out_literals() -> C: @@ -2013,7 +2013,7 @@ def test_constant_nested_struct_member_return_external_contract_call_1( a: X b: uint256 -BAR: constant(A) = A({a: X({x: 1, y: 0x0000000000000000000000000000000000012345}), b: 777}) +BAR: constant(A) = A(a=X(x=1, y=0x0000000000000000000000000000000000012345), b=777) @external def get_y() -> address: @@ -2051,7 +2051,7 @@ def test_constant_nested_struct_member_return_external_contract_call_2( b: uint256 c: bool -BAR: constant(A) = A({{a: X({{x: {i}, y: "{s}", z: b"{s}"}}), b: 777, c: True}}) +BAR: constant(A) = A(a=X(x={i}, y="{s}", z=b"{s}"), b=777, c=True) @external def get_y() -> String[{ln}]: @@ -2091,7 +2091,7 @@ def test_constant_nested_struct_member_return_external_contract_call_3( c: A d: bool -BAR: constant(C) = C({c: A({a: X({x: 1, y: -1}), b: 777}), d: True}) +BAR: constant(C) = C(c=A(a=X(x=1, y=-1), b=777), d=True) @external def get_y() -> int128: @@ -2148,7 +2148,7 @@ def foo(x: X) -> Bytes[6]: nonpayable @external def bar(addr: address) -> Bytes[6]: - _X: X = X({x: 1, y: b"hello"}) + _X: X = X(x=1, y=b"hello") return Foo(addr).foo(_X) """ @@ -2180,7 +2180,7 @@ def foo(x: X) -> String[6]: nonpayable @external def bar(addr: address) -> String[6]: - _X: X = X({x: 1, y: "hello"}) + _X: X = X(x=1, y="hello") return Foo(addr).foo(_X) """ @@ -2208,7 +2208,7 @@ def foo(b: Bytes[6]) -> Bytes[6]: nonpayable @external def bar(addr: address) -> Bytes[6]: - _X: X = X({x: 1, y: b"hello"}) + _X: X = X(x=1, y=b"hello") return Foo(addr).foo(_X.y) """ @@ -2236,7 +2236,7 @@ def foo(b: String[6]) -> String[6]: nonpayable @external def bar(addr: address) -> String[6]: - _X: X = X({x: 1, y: "hello"}) + _X: X = X(x=1, y="hello") return Foo(addr).foo(_X.y) """ @@ -2433,7 +2433,7 @@ def return_64_bytes(): def return_64_bytes() -> BoolPair: nonpayable @external def bar(foo: Foo): - t: BoolPair = foo.return_64_bytes(default_return_value=BoolPair({x: True, y:True})) + t: BoolPair = foo.return_64_bytes(default_return_value=BoolPair(x=True, y=True)) assert t.x and t.y """ bad_1 = get_contract(bad_code_1) diff --git a/tests/functional/codegen/calling_convention/test_return.py b/tests/functional/codegen/calling_convention/test_return.py index 2db3689da3..ebc600956e 100644 --- a/tests/functional/codegen/calling_convention/test_return.py +++ b/tests/functional/codegen/calling_convention/test_return.py @@ -250,7 +250,7 @@ def test_struct_return_abi(get_contract_with_gas_estimation): @external def test() -> Voter: - a: Voter = Voter({weight: 123, voted: True}) + a: Voter = Voter(weight=123, voted=True) return a """ @@ -271,7 +271,7 @@ def test_single_struct_return_abi(get_contract_with_gas_estimation): @external def test() -> Voter: - a: Voter = Voter({voted: True}) + a: Voter = Voter(voted=True) return a """ @@ -297,14 +297,14 @@ def test_struct_return(get_contract_with_gas_estimation): @internal def priv1() -> Foo: - return Foo({x: 1, y: 2}) + return Foo(x= 1, y=2) @external def pub1() -> Foo: return self.priv1() @internal def priv2() -> Foo: - foo: Foo = Foo({x: 0, y: 0}) + foo: Foo = Foo(x= 0, y=0) foo.x = 3 foo.y = 4 return foo @@ -314,12 +314,12 @@ def pub2() -> Foo: @external def pub3() -> Foo: - self._foo = Foo({x: 5, y: 6}) + self._foo = Foo(x= 5, y=6) return self._foo @external def pub4() -> Foo: - self._foos[0] = Foo({x: 7, y: 8}) + self._foos[0] = Foo(x= 7, y=8) return self._foos[0] @internal @@ -330,7 +330,7 @@ def pub5(foo: Foo) -> Foo: return self.return_arg(foo) @external def pub6() -> Foo: - foo: Foo = Foo({x: 123, y: 456}) + foo: Foo = Foo(x= 123, y=456) return self.return_arg(foo) """ foo = (123, 456) @@ -355,14 +355,14 @@ def test_single_struct_return(get_contract_with_gas_estimation): @internal def priv1() -> Foo: - return Foo({x: 1}) + return Foo(x=1) @external def pub1() -> Foo: return self.priv1() @internal def priv2() -> Foo: - foo: Foo = Foo({x: 0}) + foo: Foo = Foo(x=0) foo.x = 3 return foo @external @@ -371,12 +371,12 @@ def pub2() -> Foo: @external def pub3() -> Foo: - self._foo = Foo({x: 5}) + self._foo = Foo(x=5) return self._foo @external def pub4() -> Foo: - self._foos[0] = Foo({x: 7}) + self._foos[0] = Foo(x=7) return self._foos[0] @internal @@ -387,7 +387,7 @@ def pub5(foo: Foo) -> Foo: return self.return_arg(foo) @external def pub6() -> Foo: - foo: Foo = Foo({x: 123}) + foo: Foo = Foo(x=123) return self.return_arg(foo) """ foo = (123,) @@ -418,7 +418,7 @@ def _foo() -> uint256: @external def foo() -> Foo: - return Foo({a:1, b:2, c:self._foo(), d:4, e:5}) + return Foo(a=1, b=2, c=self._foo(), d=4, e=5) """ c = get_contract(code) @@ -438,7 +438,7 @@ def _foo() -> uint256: @external def foo() -> Foo: - return Foo({a:self._foo()}) + return Foo(a=self._foo()) """ c = get_contract(code) @@ -457,7 +457,7 @@ def test_call_in_call(get_contract): @internal def _foo(a: uint256, b: uint256, c: uint256) -> Foo: - return Foo({a:1, b:a, c:b, d:c, e:5}) + return Foo(a=1, b=a, c=b, d=c, e=5) @internal def _foo2() -> uint256: @@ -481,7 +481,7 @@ def test_call_in_call_single_struct(get_contract): @internal def _foo(a: uint256) -> Foo: - return Foo({a:a}) + return Foo(a=a) @internal def _foo2() -> uint256: @@ -512,7 +512,7 @@ def test_nested_calls_in_struct_return(get_contract): @internal def _bar(a: uint256, b: uint256, c: uint256) -> Bar: - return Bar({a:415, b:3}) + return Bar(a=415, b=3) @internal def _foo2(a: uint256) -> uint256: @@ -531,13 +531,13 @@ def _foo4() -> uint256: @external def foo() -> Foo: - return Foo({ - a:1, - b:2, - c:self._bar(6, 7, self._foo2(self._foo3(9, 11))).b, - d:self._foo4(), - e:5 - }) + return Foo( + a=1, + b=2, + c=self._bar(6, 7, self._foo2(self._foo3(9, 11))).b, + d=self._foo4(), + e=5 + ) """ c = get_contract(code) @@ -555,7 +555,7 @@ def test_nested_calls_in_single_struct_return(get_contract): @internal def _bar(a: uint256, b: uint256, c: uint256) -> Bar: - return Bar({a:415, b:3}) + return Bar(a=415, b=3) @internal def _foo2(a: uint256) -> uint256: @@ -574,9 +574,9 @@ def _foo4() -> uint256: @external def foo() -> Foo: - return Foo({ - a:self._bar(6, self._foo4(), self._foo2(self._foo3(9, 11))).b, - }) + return Foo( + a=self._bar(6, self._foo4(), self._foo2(self._foo3(9, 11))).b, + ) """ c = get_contract(code) @@ -592,7 +592,7 @@ def test_external_call_in_return_struct(get_contract): @view @external def bar() -> Bar: - return Bar({a:3, b:4}) + return Bar(a=3, b=4) """ code2 = """ @@ -610,13 +610,13 @@ def bar() -> Bar: view @external def foo(addr: address) -> Foo: - return Foo({ - a:1, - b:2, - c:IBar(addr).bar().a, - d:4, - e:5 - }) + return Foo( + a=1, + b=2, + c=IBar(addr).bar().a, + d=4, + e=5 + ) """ c = get_contract(code) @@ -632,7 +632,7 @@ def test_external_call_in_return_single_struct(get_contract): @view @external def bar() -> Bar: - return Bar({a:3}) + return Bar(a=3) """ code2 = """ @@ -645,9 +645,9 @@ def bar() -> Bar: view @external def foo(addr: address) -> Foo: - return Foo({ - a:IBar(addr).bar().a - }) + return Foo( + a=IBar(addr).bar().a + ) """ c = get_contract(code) @@ -665,7 +665,7 @@ def test_nested_external_call_in_return_struct(get_contract): @view @external def bar() -> Bar: - return Bar({a:3, b:4}) + return Bar(a=3, b=4) @view @external @@ -690,13 +690,13 @@ def baz(a: uint256) -> uint256: view @external def foo(addr: address) -> Foo: - return Foo({ - a:1, - b:2, - c:IBar(addr).bar().a, - d:4, - e:IBar(addr).baz(IBar(addr).bar().b) - }) + return Foo( + a=1, + b=2, + c=IBar(addr).bar().a, + d=4, + e=IBar(addr).baz(IBar(addr).bar().b) + ) """ c = get_contract(code) @@ -713,7 +713,7 @@ def test_nested_external_call_in_return_single_struct(get_contract): @view @external def bar() -> Bar: - return Bar({a:3}) + return Bar(a=3) @view @external @@ -733,9 +733,9 @@ def baz(a: uint256) -> uint256: view @external def foo(addr: address) -> Foo: - return Foo({ - a:IBar(addr).baz(IBar(addr).bar().a) - }) + return Foo( + a=IBar(addr).baz(IBar(addr).bar().a) + ) """ c = get_contract(code) @@ -753,7 +753,7 @@ def test_string_inside_struct(get_contract, string): @external def test_return() -> Person: - return Person({{ name:"{string}", age:42 }}) + return Person(name="{string}", age=42) """ c1 = get_contract(code) @@ -782,7 +782,7 @@ def test_string_inside_single_struct(get_contract, string): @external def test_return() -> Person: - return Person({{ name:"{string}"}}) + return Person(name="{string}") """ c1 = get_contract(code) diff --git a/tests/functional/codegen/calling_convention/test_self_call_struct.py b/tests/functional/codegen/calling_convention/test_self_call_struct.py index 98aeba6915..f3ec96f1c0 100644 --- a/tests/functional/codegen/calling_convention/test_self_call_struct.py +++ b/tests/functional/codegen/calling_convention/test_self_call_struct.py @@ -10,7 +10,7 @@ def test_call_to_self_struct(w3, get_contract): @internal @view def get_my_struct(_e1: decimal, _e2: uint256) -> MyStruct: - return MyStruct({e1: _e1, e2: _e2}) + return MyStruct(e1=_e1, e2=_e2) @external @view @@ -42,7 +42,7 @@ def test_call_to_self_struct_2(get_contract): @internal @view def get_my_struct(_e1: decimal) -> MyStruct: - return MyStruct({e1: _e1}) + return MyStruct(e1=_e1) @external @view diff --git a/tests/functional/codegen/features/decorators/test_private.py b/tests/functional/codegen/features/decorators/test_private.py index 193112f02b..15243ae3f3 100644 --- a/tests/functional/codegen/features/decorators/test_private.py +++ b/tests/functional/codegen/features/decorators/test_private.py @@ -594,7 +594,7 @@ def foo(a: int128) -> (int128, int128): @internal def _foo(_one: uint8) ->A: - return A({one: _one}) + return A(one=_one) @external def foo() -> A: @@ -611,7 +611,7 @@ def foo() -> A: @internal def _foo(_many: uint256[4], _one: uint256) -> A: - return A({many: _many, one: _one}) + return A(many=_many, one=_one) @external def foo() -> A: @@ -628,7 +628,7 @@ def foo() -> A: @internal def _foo(_many: uint256[4], _one: uint256) -> A: - return A({many: _many, one: _one}) + return A(many=_many, one=_one) @external def foo() -> (uint256[4], uint256): diff --git a/tests/functional/codegen/features/iteration/test_for_in_list.py b/tests/functional/codegen/features/iteration/test_for_in_list.py index e1bd8f313d..5d9462e7af 100644 --- a/tests/functional/codegen/features/iteration/test_for_in_list.py +++ b/tests/functional/codegen/features/iteration/test_for_in_list.py @@ -52,8 +52,8 @@ def data() -> int128: @external def data() -> int128: sss: DynArray[DynArray[S, 10], 10] = [ - [S({x:1, y:2})], - [S({x:3, y:4}), S({x:5, y:6}), S({x:7, y:8}), S({x:9, y:10})] + [S(x=1, y=2)], + [S(x=3, y=4), S(x=5, y=6), S(x=7, y=8), S(x=9, y=10)] ] ret: int128 = 0 for ss: DynArray[S, 10] in sss: @@ -133,7 +133,7 @@ def data() -> int128: @external def data() -> int128: ret: int128 = 0 - for ss: S[1] in [[S({x:1, y:2})]]: + for ss: S[1] in [[S(x=1, y=2)]]: for s: S in ss: ret += s.x + s.y return ret""", diff --git a/tests/functional/codegen/features/test_assignment.py b/tests/functional/codegen/features/test_assignment.py index aebb13eefa..a276eb7ea9 100644 --- a/tests/functional/codegen/features/test_assignment.py +++ b/tests/functional/codegen/features/test_assignment.py @@ -78,7 +78,7 @@ def test_internal_assign_struct(get_contract_with_gas_estimation): @internal def foo(x: Foo) -> Foo: - x = Foo({a: 789, b: [Bar.BAZ, Bar.BAK, Bar.BAD], c: \"conda\"}) + x = Foo(a=789, b=[Bar.BAZ, Bar.BAK, Bar.BAD], c=\"conda\") return x @external @@ -437,7 +437,7 @@ def test_assign_rhs_lhs_overlap_struct(get_contract): @external def bug(p: Point) -> Point: t: Point = p - t = Point({x: t.y, y: t.x}) + t = Point(x=t.y, y=t.x) return t """ c = get_contract(code) diff --git a/tests/functional/codegen/features/test_bytes_map_keys.py b/tests/functional/codegen/features/test_bytes_map_keys.py index 22df767f02..c70ffb26ce 100644 --- a/tests/functional/codegen/features/test_bytes_map_keys.py +++ b/tests/functional/codegen/features/test_bytes_map_keys.py @@ -121,12 +121,12 @@ def __init__(): @external def get_one() -> int128: - b: Foo = Foo({one: b"hello", two: b"potato"}) + b: Foo = Foo(one=b"hello", two=b"potato") return self.a[b.one] @external def get_two() -> int128: - b: Foo = Foo({one: b"hello", two: b"potato"}) + b: Foo = Foo(one=b"hello", two=b"potato") return self.a[b.two] """ @@ -149,7 +149,7 @@ def test_struct_bytes_key_storage(get_contract): def __init__(): self.a[b"hello"] = 1069 self.a[b"potato"] = 31337 - self.b = Foo({one: b"hello", two: b"potato"}) + self.b = Foo(one=b"hello", two=b"potato") @external def get_one() -> int128: @@ -218,7 +218,7 @@ def test_struct_bytes_hashmap_as_key_in_other_hashmap(get_contract): @deploy def __init__(): self.foo[b"hello"] = 31337 - self.bar[12] = Thing({name: b"hello"}) + self.bar[12] = Thing(name=b"hello") @external def do_the_thing(_index: uint256) -> uint256: diff --git a/tests/functional/codegen/features/test_immutable.py b/tests/functional/codegen/features/test_immutable.py index d0bc47c238..49ff54b353 100644 --- a/tests/functional/codegen/features/test_immutable.py +++ b/tests/functional/codegen/features/test_immutable.py @@ -91,12 +91,12 @@ def test_struct_immutable(get_contract): @deploy def __init__(_a: uint256, _b: uint256, _c: address, _d: int256): - my_struct = MyStruct({ - a: _a, - b: _b, - c: _c, - d: _d - }) + my_struct = MyStruct( + a=_a, + b=_b, + c=_c, + d=_d + ) @view @external @@ -117,7 +117,7 @@ def test_complex_immutable_modifiable(get_contract): @deploy def __init__(a: uint256): - my_struct = MyStruct({a: a}) + my_struct = MyStruct(a=a) # struct members are modifiable after initialization my_struct.a += 1 diff --git a/tests/functional/codegen/features/test_internal_call.py b/tests/functional/codegen/features/test_internal_call.py index 422f53fdeb..8320922e8e 100644 --- a/tests/functional/codegen/features/test_internal_call.py +++ b/tests/functional/codegen/features/test_internal_call.py @@ -550,7 +550,7 @@ def test_struct_return_1(get_contract_with_gas_estimation, i, ln, s): @internal def get_struct_x() -> X: - return X({{x: {i}, y: "{s}", z: b"{s}"}}) + return X(x={i}, y="{s}", z=b"{s}") @external def test() -> (int128, String[{ln}], Bytes[{ln}]): @@ -575,7 +575,7 @@ def _foo(x: X) -> Bytes[6]: @external def bar() -> Bytes[6]: - _X: X = X({x: 1, y: b"hello"}) + _X: X = X(x=1, y=b"hello") return self._foo(_X) """ @@ -596,7 +596,7 @@ def _foo(x: X) -> String[6]: @external def bar() -> String[6]: - _X: X = X({x: 1, y: "hello"}) + _X: X = X(x=1, y="hello") return self._foo(_X) """ @@ -617,7 +617,7 @@ def _foo(s: Bytes[6]) -> Bytes[6]: @external def bar() -> Bytes[6]: - _X: X = X({x: 1, y: b"hello"}) + _X: X = X(x=1, y=b"hello") return self._foo(_X.y) """ @@ -638,7 +638,7 @@ def _foo(s: String[6]) -> String[6]: @external def bar() -> String[6]: - _X: X = X({x: 1, y: "hello"}) + _X: X = X(x=1, y="hello") return self._foo(_X.y) """ diff --git a/tests/functional/codegen/features/test_logging.py b/tests/functional/codegen/features/test_logging.py index 8b80811d02..cf64d271a9 100644 --- a/tests/functional/codegen/features/test_logging.py +++ b/tests/functional/codegen/features/test_logging.py @@ -493,7 +493,7 @@ def test_event_logging_with_multiple_logs_topics_and_data( @external def foo(): log MyLog(1, b'bar') - log YourLog(self, MyStruct({x: 1, y: b'abc', z: SmallStruct({t: 'house', w: 13.5})})) + log YourLog(self, MyStruct(x=1, y=b'abc', z=SmallStruct(t='house', w=13.5))) """ c = get_contract_with_gas_estimation(loggy_code) diff --git a/tests/functional/codegen/features/test_packing.py b/tests/functional/codegen/features/test_packing.py index bb3ccecbd8..3a18b5e88b 100644 --- a/tests/functional/codegen/features/test_packing.py +++ b/tests/functional/codegen/features/test_packing.py @@ -30,7 +30,7 @@ def foo() -> int128: def fop() -> int128: _x: int128 = 0 _y: int128[5] = [0, 0, 0, 0, 0] - _z: Z = Z({foo: [0, 0, 0], bar: [Bar({a: 0, b: 0}), Bar({a: 0, b: 0})]}) + _z: Z = Z(foo=[0, 0, 0], bar=[Bar(a=0, b=0), Bar(a=0, b=0)]) _a: int128 = 0 _x = 1 _y[0] = 2 diff --git a/tests/functional/codegen/integration/test_crowdfund.py b/tests/functional/codegen/integration/test_crowdfund.py index 1a8b3f7e9f..b07ce5dc22 100644 --- a/tests/functional/codegen/integration/test_crowdfund.py +++ b/tests/functional/codegen/integration/test_crowdfund.py @@ -121,7 +121,7 @@ def __init__(_beneficiary: address, _goal: uint256, _timelimit: uint256): def participate(): assert block.timestamp < self.deadline nfi: int128 = self.nextFunderIndex - self.funders[nfi] = Funder({sender: msg.sender, value: msg.value}) + self.funders[nfi] = Funder(sender=msg.sender, value=msg.value) self.nextFunderIndex = nfi + 1 @external diff --git a/tests/functional/codegen/modules/test_stateless_functions.py b/tests/functional/codegen/modules/test_stateless_functions.py index 26c3f338fb..722b287d98 100644 --- a/tests/functional/codegen/modules/test_stateless_functions.py +++ b/tests/functional/codegen/modules/test_stateless_functions.py @@ -159,7 +159,7 @@ def test_library_structs(get_contract, make_input_bundle): @internal def foo() -> SomeStruct: - return SomeStruct({x: 1}) + return SomeStruct(x=1) """ contract_source = """ import library @@ -170,7 +170,7 @@ def bar(s: library.SomeStruct): @external def baz() -> library.SomeStruct: - return library.SomeStruct({x: 2}) + return library.SomeStruct(x=2) @external def qux() -> library.SomeStruct: diff --git a/tests/functional/codegen/storage_variables/test_setters.py b/tests/functional/codegen/storage_variables/test_setters.py index 119157977a..cf4138b939 100644 --- a/tests/functional/codegen/storage_variables/test_setters.py +++ b/tests/functional/codegen/storage_variables/test_setters.py @@ -91,16 +91,16 @@ def test_multi_setter_struct_test(get_contract_with_gas_estimation): @external def foo() -> int128: foo0: int128 = 1 - self.dog[0] = Dog({foo: foo0, bar: 2}) - self.dog[1] = Dog({foo: 3, bar: 4}) - self.dog[2] = Dog({foo: 5, bar: 6}) + self.dog[0] = Dog(foo=foo0, bar=2) + self.dog[1] = Dog(foo=3, bar=4) + self.dog[2] = Dog(foo=5, bar=6) return self.dog[0].foo + self.dog[0].bar * 10 + self.dog[1].foo * 100 + \ self.dog[1].bar * 1000 + self.dog[2].foo * 10000 + self.dog[2].bar * 100000 @external def fop() -> int128: - self.z = [Z({foo: [1, 2, 3], bar: [Bar({a: 4, b: 5}), Bar({a: 2, b: 3})]}), - Z({foo: [6, 7, 8], bar: [Bar({a: 9, b: 1}), Bar({a: 7, b: 8})]})] + self.z = [Z(foo=[1, 2, 3], bar=[Bar(a=4, b=5), Bar(a=2, b=3)]), + Z(foo=[6, 7, 8], bar=[Bar(a=9, b=1), Bar(a=7, b=8)])] return self.z[0].foo[0] + self.z[0].foo[1] * 10 + self.z[0].foo[2] * 100 + \ self.z[0].bar[0].a * 1000 + \ self.z[0].bar[0].b * 10000 + \ @@ -116,15 +116,15 @@ def fop() -> int128: @external def goo() -> int128: - god: Goo[3] = [Goo({foo: 1, bar: 2}), Goo({foo: 3, bar: 4}), Goo({foo: 5, bar: 6})] + god: Goo[3] = [Goo(foo=1, bar=2), Goo(foo=3, bar=4), Goo(foo=5, bar=6)] return god[0].foo + god[0].bar * 10 + god[1].foo * 100 + \ god[1].bar * 1000 + god[2].foo * 10000 + god[2].bar * 100000 @external def gop() -> int128: zed: Zed[2] = [ - Zed({foo: [1, 2, 3], bar: [Bar({a: 4, b: 5}), Bar({a: 2, b: 3})]}), - Zed({foo: [6, 7, 8], bar: [Bar({a: 9, b: 1}), Bar({a: 7, b: 8})]}) + Zed(foo=[1, 2, 3], bar=[Bar(a=4, b=5), Bar(a=2, b=3)]), + Zed(foo=[6, 7, 8], bar=[Bar(a=9, b=1), Bar(a=7, b=8)]) ] return zed[0].foo[0] + zed[0].foo[1] * 10 + \ zed[0].foo[2] * 100 + \ @@ -157,7 +157,7 @@ def test_struct_assignment_order(get_contract, assert_compile_failed): @external @view def test2() -> uint256: - foo: Foo = Foo({b: 2, a: 297}) + foo: Foo = Foo(b=2, a=297) return foo.a """ assert_compile_failed(lambda: get_contract(code), InvalidAttribute) @@ -193,25 +193,25 @@ def test_composite_setter_test(get_contract_with_gas_estimation): @external def foo() -> int128: - self.mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4}) - non: C = C({c: 5}) + self.mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4) + non: C = C(c=5) self.mom.a[0] = non - non = C({c: 6}) + non = C(c=6) self.mom.a[2] = non return self.mom.a[0].c + self.mom.a[1].c * 10 + self.mom.a[2].c * 100 + self.mom.b * 1000 @external def fop() -> int128: - popp: Mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4}) - self.qoq = C({c: 5}) + popp: Mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4) + self.qoq = C(c=5) popp.a[0] = self.qoq - self.qoq = C({c: 6}) + self.qoq = C(c=6) popp.a[2] = self.qoq return popp.a[0].c + popp.a[1].c * 10 + popp.a[2].c * 100 + popp.b * 1000 @external def foq() -> int128: - popp: Mom = Mom({a: [C({c: 1}), C({c: 2}), C({c: 3})], b: 4}) + popp: Mom = Mom(a=[C(c=1), C(c=2), C(c=3)], b=4) popp.a[0] = empty(C) popp.a[2] = empty(C) return popp.a[0].c + popp.a[1].c * 10 + popp.a[2].c * 100 + popp.b * 1000 diff --git a/tests/functional/codegen/types/test_bytes.py b/tests/functional/codegen/types/test_bytes.py index 99e5835f6e..f8ae65cc54 100644 --- a/tests/functional/codegen/types/test_bytes.py +++ b/tests/functional/codegen/types/test_bytes.py @@ -132,7 +132,7 @@ def test_test_bytes5(get_contract_with_gas_estimation): @external def foo(inp1: Bytes[40], inp2: Bytes[45]): - self.g = G({a: inp1, b: inp2}) + self.g = G(a=inp1, b=inp2) @external def check1() -> Bytes[50]: @@ -144,17 +144,17 @@ def check2() -> Bytes[50]: @external def bar(inp1: Bytes[40], inp2: Bytes[45]) -> Bytes[50]: - h: H = H({a: inp1, b: inp2}) + h: H = H(a=inp1, b=inp2) return h.a @external def bat(inp1: Bytes[40], inp2: Bytes[45]) -> Bytes[50]: - h: H = H({a: inp1, b: inp2}) + h: H = H(a=inp1, b=inp2) return h.b @external def quz(inp1: Bytes[40], inp2: Bytes[45]): - h: H = H({a: inp1, b: inp2}) + h: H = H(a=inp1, b=inp2) self.g.a = h.a self.g.b = h.b """ diff --git a/tests/functional/codegen/types/test_dynamic_array.py b/tests/functional/codegen/types/test_dynamic_array.py index fc3223caaf..b55f07639b 100644 --- a/tests/functional/codegen/types/test_dynamic_array.py +++ b/tests/functional/codegen/types/test_dynamic_array.py @@ -1362,12 +1362,12 @@ def test_list_of_structs_lists_with_nested_lists(get_contract, tx_failed): def foo(x: uint8) -> uint8: b: DynArray[Bar[2], 2] = [ [ - Bar({a: [[x, x + 1], [x + 2, x + 3]]}), - Bar({a: [[x + 4, x +5], [x + 6, x + 7]]}) + Bar(a=[[x, x + 1], [x + 2, x + 3]]), + Bar(a=[[x + 4, x +5], [x + 6, x + 7]]) ], [ - Bar({a: [[x + 8, x + 9], [x + 10, x + 11]]}), - Bar({a: [[x + 12, x + 13], [x + 14, x + 15]]}) + Bar(a=[[x + 8, x + 9], [x + 10, x + 11]]), + Bar(a=[[x + 12, x + 13], [x + 14, x + 15]]) ], ] return b[0][0].a[0][0] + b[0][1].a[1][1] + b[1][0].a[0][1] + b[1][1].a[1][0] @@ -1503,11 +1503,11 @@ def _foo3() -> DynArray[DynArray[DynArray[uint256, 2], 2], 2]: @external def bar() -> DynArray[DynArray[DynArray[uint256, 2], 2], 2]: - foo: Foo = Foo({ - a1: self._foo(), - a2: self._foo2(), - a3: self._foo3(), - }) + foo: Foo = Foo( + a1=self._foo(), + a2=self._foo2(), + a3=self._foo3(), + ) return foo.a3 """ c = get_contract(code) @@ -1524,12 +1524,12 @@ def test_struct_of_lists_2(get_contract): @internal def _foo(x: int128) -> Foo: - f: Foo = Foo({ - b: b"hello", - da: [x, x * 2], - sa: [x + 1, x + 2, x + 3, x + 4, x + 5], - some_int: x - 1 - }) + f: Foo = Foo( + b=b"hello", + da=[x, x * 2], + sa=[x + 1, x + 2, x + 3, x + 4, x + 5], + some_int=x - 1 + ) return f @external @@ -1550,12 +1550,11 @@ def test_struct_of_lists_3(get_contract): @internal def _foo(x: int128) -> Foo: - f: Foo = Foo({ - a: [x, x * 2], - b: [0x0000000000000000000000000000000000000012], - c: [False, True, False] - - }) + f: Foo = Foo( + a=[x, x * 2], + b=[0x0000000000000000000000000000000000000012], + c=[False, True, False] + ) return f @external @@ -1577,15 +1576,15 @@ def test_nested_struct_of_lists(get_contract, assert_compile_failed, optimize): @internal def _foo() -> nestedFoo: - return nestedFoo({a1: [ + return nestedFoo(a1=[ [[3, 7], [7, 3]], [[7, 3], [3, 7]], - ]}) + ]) @internal def _foo2() -> Foo: _nF1: nestedFoo = self._foo() - return Foo({b1: [[[_nF1, _nF1], [_nF1, _nF1]], [[_nF1, _nF1], [_nF1, _nF1]]]}) + return Foo(b1=[[[_nF1, _nF1], [_nF1, _nF1]], [[_nF1, _nF1], [_nF1, _nF1]]]) @internal def _foo3(f: Foo) -> Foo: diff --git a/tests/functional/codegen/types/test_flag.py b/tests/functional/codegen/types/test_flag.py index dd9c867a96..68aab1968f 100644 --- a/tests/functional/codegen/types/test_flag.py +++ b/tests/functional/codegen/types/test_flag.py @@ -281,7 +281,7 @@ def test_struct_with_flag(get_contract_with_gas_estimation): @external def get_flag_from_struct() -> Foobar: - f: Foo = Foo({a: 1, b: Foobar.BAR}) + f: Foo = Foo(a=1, b=Foobar.BAR) return f.b """ c = get_contract_with_gas_estimation(code) diff --git a/tests/functional/syntax/exceptions/test_syntax_exception.py b/tests/functional/syntax/exceptions/test_syntax_exception.py index 53a9550a7d..80f499ac89 100644 --- a/tests/functional/syntax/exceptions/test_syntax_exception.py +++ b/tests/functional/syntax/exceptions/test_syntax_exception.py @@ -98,6 +98,11 @@ def foo(): for i: $$$ in range(0, 10): pass """, + """ +struct S: + x: int128 +s: S = S(x=int128, 1) + """, ] diff --git a/tests/functional/syntax/exceptions/test_variable_declaration_exception.py b/tests/functional/syntax/exceptions/test_variable_declaration_exception.py index f34c9a33c4..42c48dbe32 100644 --- a/tests/functional/syntax/exceptions/test_variable_declaration_exception.py +++ b/tests/functional/syntax/exceptions/test_variable_declaration_exception.py @@ -13,11 +13,6 @@ def foo() -> int128: """ struct S: x: int128 -s: S = S({x: int128}, 1) - """, - """ -struct S: - x: int128 s: S = S() """, """ diff --git a/tests/functional/syntax/test_ann_assign.py b/tests/functional/syntax/test_ann_assign.py index 7fdb1328c2..23ebeb9560 100644 --- a/tests/functional/syntax/test_ann_assign.py +++ b/tests/functional/syntax/test_ann_assign.py @@ -59,7 +59,7 @@ def data() -> int128: b: decimal @external def foo() -> int128: - s: S = S({a: 1.2, b: 1}) + s: S = S(a=1.2, b=1) return s.a """, TypeMismatch, @@ -71,7 +71,7 @@ def foo() -> int128: b: decimal @external def foo() -> int128: - s: S = S({a: 1}) + s: S = S(a=1) """, VariableDeclarationException, ), @@ -82,7 +82,7 @@ def foo() -> int128: b: decimal @external def foo() -> int128: - s: S = S({b: 1.2, a: 1}) + s: S = S(b=1.2, a=1) """, InvalidAttribute, ), @@ -93,7 +93,7 @@ def foo() -> int128: b: decimal @external def foo() -> int128: - s: S = S({a: 1, b: 1.2, c: 1, d: 33, e: 55}) + s: S = S(a=1, b=1.2, c=1, d=33, e=55) return s.a """, UnknownAttribute, diff --git a/tests/functional/syntax/test_block.py b/tests/functional/syntax/test_block.py index 8d8bffb697..aea39aa9c7 100644 --- a/tests/functional/syntax/test_block.py +++ b/tests/functional/syntax/test_block.py @@ -63,8 +63,8 @@ def add_record(): y: int128 @external def add_record(): - a: X = X({x: block.timestamp}) - b: Y = Y({y: 5}) + a: X = X(x=block.timestamp) + b: Y = Y(y=5) a.x = b.y """, """ @@ -123,7 +123,7 @@ def foo(): x: uint256 @external def add_record(): - a: X = X({x: block.timestamp}) + a: X = X(x=block.timestamp) a.x = block.gaslimit a.x = block.basefee a.x = 5 diff --git a/tests/functional/syntax/test_constants.py b/tests/functional/syntax/test_constants.py index 63abf24485..5eb9eefe25 100644 --- a/tests/functional/syntax/test_constants.py +++ b/tests/functional/syntax/test_constants.py @@ -135,7 +135,7 @@ def test(VAL: uint256): a: uint256 b: uint256 -CONST_BAR: constant(Foo) = Foo({a: 1, b: block.number}) +CONST_BAR: constant(Foo) = Foo(a=1, b=block.number) """, StateAccessViolation, ), @@ -163,7 +163,7 @@ def foo() -> uint256: struct Foo: a : uint256 -x: constant(Foo) = Foo({a: 1}) +x: constant(Foo) = Foo(a=1) @external def hello() : @@ -276,7 +276,7 @@ def deposit(deposit_input: Bytes[2048]): a: uint256 b: uint256 -CONST_BAR: constant(Foo) = Foo({a: 1, b: 2}) +CONST_BAR: constant(Foo) = Foo(a=1, b=2) """, """ CONST_EMPTY: constant(bytes32) = empty(bytes32) @@ -293,7 +293,7 @@ def foo() -> bytes32: A: constant(uint256) = 1 B: constant(uint256) = 2 -CONST_BAR: constant(Foo) = Foo({a: A, b: B}) +CONST_BAR: constant(Foo) = Foo(a=A, b=B) """, """ struct Foo: @@ -306,10 +306,10 @@ def foo() -> bytes32: A: constant(uint256) = 1 B: constant(uint256) = 2 -C: constant(Foo) = Foo({a: A, b: B}) +C: constant(Foo) = Foo(a=A, b=B) D: constant(int128) = -1 -CONST_BAR: constant(Bar) = Bar({c: C, d: D}) +CONST_BAR: constant(Bar) = Bar(c=C, d=D) """, """ interface Foo: diff --git a/tests/functional/syntax/test_flag.py b/tests/functional/syntax/test_flag.py index 22309502b7..7732ccc39f 100644 --- a/tests/functional/syntax/test_flag.py +++ b/tests/functional/syntax/test_flag.py @@ -158,10 +158,10 @@ def run() -> Action: @external def run() -> Order: - return Order({ - action: Action.BUY, - amount: 10**18 - }) + return Order( + action=Action.BUY, + amount=10**18 + ) """, "flag Foo:\n" + "\n".join([f" member{i}" for i in range(256)]), """ diff --git a/tests/functional/syntax/test_immutables.py b/tests/functional/syntax/test_immutables.py index 59fb1a69d9..7e5903a6a1 100644 --- a/tests/functional/syntax/test_immutables.py +++ b/tests/functional/syntax/test_immutables.py @@ -165,7 +165,7 @@ def report(): @deploy def __init__(): - x = Foo({a:1}) + x = Foo(a=1) @external def hello() : diff --git a/tests/functional/syntax/test_invalids.py b/tests/functional/syntax/test_invalids.py index dfc74fc75b..f4e60902ef 100644 --- a/tests/functional/syntax/test_invalids.py +++ b/tests/functional/syntax/test_invalids.py @@ -357,7 +357,7 @@ def a(): @external def a(): - x: int128 = StructX({y: 1}) + x: int128 = StructX(y=1) """, UnknownAttribute, ) diff --git a/tests/functional/syntax/test_no_none.py b/tests/functional/syntax/test_no_none.py index 085ce395ab..ebe32816bd 100644 --- a/tests/functional/syntax/test_no_none.py +++ b/tests/functional/syntax/test_no_none.py @@ -178,7 +178,7 @@ def test_struct_none(assert_compile_failed, get_contract_with_gas_estimation): @external def foo(): - mom: Mom = Mom({a: None, b: 0}) + mom: Mom = Mom(a=None, b=0) """, """ struct Mom: @@ -187,7 +187,7 @@ def foo(): @external def foo(): - mom: Mom = Mom({a: 0, b: None}) + mom: Mom = Mom(a=0, b=None) """, """ struct Mom: @@ -196,7 +196,7 @@ def foo(): @external def foo(): - mom: Mom = Mom({a: None, b: None}) + mom: Mom = Mom(a=None, b=None) """, ] diff --git a/tests/functional/syntax/test_structs.py b/tests/functional/syntax/test_structs.py index 4fad35d1d4..c2cc11324f 100644 --- a/tests/functional/syntax/test_structs.py +++ b/tests/functional/syntax/test_structs.py @@ -1,17 +1,19 @@ +import warnings + import pytest from vyper import compiler from vyper.exceptions import ( InstantiationException, StructureException, + SyntaxException, TypeMismatch, UnknownAttribute, VariableDeclarationException, ) fail_list = [ - ( - """ + """ struct A: x: int128 a: A @@ -19,8 +21,6 @@ def foo(): self.a = A(1) """, - VariableDeclarationException, - ), ( """ struct A: @@ -28,24 +28,20 @@ def foo(): a: A @external def foo(): - self.a = A({x: 1, y: 2}) + self.a = A(x=1, y=2) """, UnknownAttribute, ), - ( - """ + """ struct A: x: int128 y: int128 a: A @external def foo(): - self.a = A({x: 1}) + self.a = A(x=1) """, - VariableDeclarationException, - ), - ( - """ + """ struct A: x: int128 struct B: @@ -56,10 +52,7 @@ def foo(): def foo(): self.a = A(self.b) """, - VariableDeclarationException, - ), - ( - """ + """ struct A: x: int128 a: A @@ -68,10 +61,7 @@ def foo(): def foo(): self.a = A(self.b) """, - VariableDeclarationException, - ), - ( - """ + """ struct A: x: int128 y: int128 @@ -80,10 +70,7 @@ def foo(): def foo(): self.a = A({x: 1}) """, - VariableDeclarationException, - ), - ( - """ + """ struct C: c: int128 struct Mom: @@ -98,8 +85,6 @@ def foo(): def foo(): self.nom = Nom(self.mom) """, - VariableDeclarationException, - ), """ struct C1: c: int128 @@ -178,6 +163,15 @@ def foo(): def foo(): self.nom = Nom(self.mom) """, + """ +struct Foo: + a: uint256 + b: uint256 + +@external +def foo(i: uint256, j: uint256): + f: Foo = Foo(i, b=j) + """, ( """ struct Mom: @@ -251,7 +245,7 @@ def foo(): nom: C[3] @external def foo(): - self.mom = Mom({a: self.nom, b: 5.5}) + self.mom = Mom(a=self.nom, b=5.5) """, TypeMismatch, ), @@ -268,7 +262,7 @@ def foo(): nom: C2[3] @external def foo(): - self.mom = Mom({a: self.nom, b: 5}) + self.mom = Mom(a=self.nom, b=5) """, TypeMismatch, ), @@ -285,7 +279,7 @@ def foo(): nom: C[3] @external def foo(): - self.mom = Mom({a: self.nom, b: self.nom}) + self.mom = Mom(a=self.nom, b=self.nom) """, TypeMismatch, ), @@ -329,7 +323,7 @@ def foo(): nom: C2[3] @external def foo(): - self.mom = Mom({a: self.nom, b: 5}) + self.mom = Mom(a=self.nom, b=5) """, TypeMismatch, ), @@ -342,9 +336,9 @@ def foo(): bar: int128[3] @external def foo(): - self.bar = Bar({0: 5, 1: 7, 2: 9}) + self.bar = Bar(0=5, 1=7, 2=9) """, - UnknownAttribute, + SyntaxException, ), ( """ @@ -355,7 +349,7 @@ def foo(): bar: int128[3] @external def foo(): - self.bar = Bar({a: 5, b: 7, c: 9}) + self.bar = Bar(a=5, b=7, c=9) """, TypeMismatch, ), @@ -366,7 +360,7 @@ def foo(): dog: int128 @external def foo() -> int128: - f: Farm = Farm({cow: 5, dog: 7}) + f: Farm = Farm(cow=5, dog=7) return f """, TypeMismatch, @@ -390,7 +384,7 @@ def foo(): b: B @external def foo(): - self.b = B({foo: 1, foo: 2}) + self.b = B(foo=1, foo=2) """, UnknownAttribute, ), @@ -425,7 +419,7 @@ def foo(): @external def foo(): - Foo({a: 1}) + Foo(a=1) """, StructureException, ), @@ -459,7 +453,7 @@ def test_block_fail(bad_code): a: A @external def foo(): - self.a = A({x: 1}) + self.a = A(x=1) """, """ struct C: @@ -482,7 +476,7 @@ def foo(): nom: C[3] @external def foo(): - mom: Mom = Mom({a:[C({c:0}), C({c:0}), C({c:0})], b: 0}) + mom: Mom = Mom(a=[C(c=0), C(c=0), C(c=0)], b=0) mom.a = self.nom """, """ @@ -495,7 +489,7 @@ def foo(): nom: C[3] @external def foo(): - self.mom = Mom({a: self.nom, b: 5}) + self.mom = Mom(a=self.nom, b=5) """, """ struct C: @@ -507,7 +501,7 @@ def foo(): nom: C[3] @external def foo(): - self.mom = Mom({a: self.nom, b: 5}) + self.mom = Mom(a=self.nom, b=5) """, """ struct C: @@ -518,8 +512,8 @@ def foo(): mom: Mom @external def foo(): - nom: C[3] = [C({c:0}), C({c:0}), C({c:0})] - self.mom = Mom({a: nom, b: 5}) + nom: C[3] = [C(c=0), C(c=0), C(c=0)] + self.mom = Mom(a=nom, b=5) """, """ struct B: @@ -548,7 +542,7 @@ def foo(): d: bool @external def get_y() -> int128: - return C({c: A({a: X({x: 1, y: -1}), b: 777}), d: True}).c.a.y - 10 + return C(c=A(a=X(x=1, y=-1), b=777), d=True).c.a.y - 10 """, """ struct X: @@ -560,7 +554,7 @@ def get_y() -> int128: struct C: c: A d: bool -FOO: constant(C) = C({c: A({a: X({x: 1, y: -1}), b: 777}), d: True}) +FOO: constant(C) = C(c=A(a=X(x=1, y=-1), b=777), d=True) @external def get_y() -> int128: return FOO.c.a.y - 10 @@ -572,7 +566,7 @@ def get_y() -> int128: @external def foo(): - bar: C = C({a: 1, b: block.timestamp}) + bar: C = C(a=1, b=block.timestamp) """, ] @@ -580,3 +574,24 @@ def foo(): @pytest.mark.parametrize("good_code", valid_list) def test_block_success(good_code): assert compiler.compile_code(good_code) is not None + + +def test_old_constructor_syntax(): + # backwards compatibility for vyper <0.4.0 + code = """ +struct A: + x: int128 +a: A +@external +def foo(): + self.a = A({x: 1}) + """ + with warnings.catch_warnings(record=True) as w: + assert compiler.compile_code(code) is not None + + expected = "Instantiating a struct using a dictionary is deprecated " + expected += "as of v0.4.0 and will be disallowed in a future release. " + expected += "Use kwargs instead e.g. Foo(a=1, b=2)" + + assert len(w) == 1 + assert str(w[0].message) == expected diff --git a/tests/unit/cli/vyper_compile/test_compile_files.py b/tests/unit/cli/vyper_compile/test_compile_files.py index 6adee24db6..bc99b07a8e 100644 --- a/tests/unit/cli/vyper_compile/test_compile_files.py +++ b/tests/unit/cli/vyper_compile/test_compile_files.py @@ -38,7 +38,7 @@ def test_invalid_root_path(): @external def foo() -> {alias}.FooStruct: - return {alias}.FooStruct({{foo_: 13}}) + return {alias}.FooStruct(foo_=13) @external def bar(a: address) -> {alias}.FooStruct: @@ -176,7 +176,7 @@ def know_thyself(a: address) -> ISelf.FooStruct: @external def be_known() -> ISelf.FooStruct: - return ISelf.FooStruct({{foo_: 42}}) + return ISelf.FooStruct(foo_=42) """ make_file("contracts/ISelf.vyi", interface_code) meta = make_file("contracts/Self.vy", code) diff --git a/tests/unit/semantics/analysis/test_for_loop.py b/tests/unit/semantics/analysis/test_for_loop.py index c97c9c095e..bc4ae1a2f7 100644 --- a/tests/unit/semantics/analysis/test_for_loop.py +++ b/tests/unit/semantics/analysis/test_for_loop.py @@ -171,7 +171,7 @@ def test_modify_iterator_through_struct(dummy_input_bundle): def foo(): self.a.iter = [1, 2, 3] for i: uint256 in self.a.iter: - self.a = A({iter: [1, 2, 3, 4]}) + self.a = A(iter=[1, 2, 3, 4]) """ vyper_module = parse_to_ast(code) with pytest.raises(ImmutableViolation) as e: diff --git a/tests/unit/semantics/test_storage_slots.py b/tests/unit/semantics/test_storage_slots.py index 1dc70fd1ba..7cbe71cf29 100644 --- a/tests/unit/semantics/test_storage_slots.py +++ b/tests/unit/semantics/test_storage_slots.py @@ -27,19 +27,19 @@ @deploy def __init__(): - self.a = StructOne({a: "ok", b: [4,5,6]}) + self.a = StructOne(a="ok", b=[4,5,6]) self.b = [7, 8] self.c = b"thisisthirtytwobytesokhowdoyoudo" self.d = [-1, -2, -3, -4] self.e = "A realllllly long string but we won't use it all" self.f = [33] self.g = [ - StructTwo({a: b"hello", b: [-66, 420], c: "another string"}), - StructTwo({ - a: b"gbye", - b: [1337, 888], - c: "whatifthisstringtakesuptheentirelengthwouldthatbesobadidothinkso" - }) + StructTwo(a=b"hello", b=[-66, 420], c="another string"), + StructTwo( + a=b"gbye", + b=[1337, 888], + c="whatifthisstringtakesuptheentirelengthwouldthatbesobadidothinkso" + ) ] self.dyn_array = [1, 2, 3] self.h = [123456789] diff --git a/vyper/ast/parse.py b/vyper/ast/parse.py index a10a840da0..4f162ac18f 100644 --- a/vyper/ast/parse.py +++ b/vyper/ast/parse.py @@ -1,5 +1,6 @@ import ast as python_ast import tokenize +import warnings from decimal import Decimal from typing import Any, Dict, List, Optional, Union, cast @@ -341,6 +342,29 @@ def visit_Expr(self, node): return node + def visit_Call(self, node): + # Convert structs declared as `Dict` node for vyper < 0.4.0 to kwargs + if len(node.args) == 1 and isinstance(node.args[0], python_ast.Dict): + msg = "Instantiating a struct using a dictionary is deprecated " + msg += "as of v0.4.0 and will be disallowed in a future release. " + msg += "Use kwargs instead e.g. Foo(a=1, b=2)" + warnings.warn(msg, stacklevel=2) + + dict_ = node.args[0] + kw_list = [] + + assert len(dict_.keys) == len(dict_.values) + for key, value in zip(dict_.keys, dict_.values): + replacement_kw_node = python_ast.keyword(key.id, value) + kw_list.append(replacement_kw_node) + + node.args = [] + node.keywords = kw_list + + self.generic_visit(node) + + return node + def visit_Constant(self, node): """ Handle `Constant` when using Python >=3.8 diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index 9c7f11dcb3..13e1309e6d 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -683,9 +683,7 @@ def parse_Call(self): # Struct constructor if is_type_t(func_type, StructT): - args = self.expr.args - if len(args) == 1 and isinstance(args[0], vy_ast.Dict): - return Expr.struct_literals(args[0], self.context, self.expr._metadata["type"]) + return self.handle_struct_literal() # Interface constructor. Bar(
). if is_type_t(func_type, InterfaceT): @@ -750,17 +748,15 @@ def parse_IfExp(self): location = body.location return IRnode.from_list(["if", test, body, orelse], typ=typ, location=location) - @staticmethod - def struct_literals(expr, context, typ): + def handle_struct_literal(self): + expr = self.expr + typ = expr._metadata["type"] member_subs = {} - member_typs = {} - for key, value in zip(expr.keys, expr.values): - assert isinstance(key, vy_ast.Name) - assert key.id not in member_subs - - sub = Expr(value, context).ir_node - member_subs[key.id] = sub - member_typs[key.id] = sub.typ + for kwarg in expr.keywords: + assert kwarg.arg not in member_subs + + sub = Expr(kwarg.value, self.context).ir_node + member_subs[kwarg.arg] = sub return IRnode.from_list( ["multi"] + [member_subs[key] for key in member_subs.keys()], typ=typ diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index 39a1c59290..cc08b3b95a 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -731,8 +731,8 @@ def visit_Call(self, node: vy_ast.Call, typ: VyperType) -> None: # struct ctors # ctors have no kwargs expected_types = func_type.typedef.members.values() # type: ignore - for value, arg_type in zip(node.args[0].values, expected_types): - self.visit(value, arg_type) + for kwarg, arg_type in zip(node.keywords, expected_types): + self.visit(kwarg.value, arg_type) elif isinstance(func_type, MemberFunctionT): if func_type.is_modifying and self.function_analyzer is not None: # TODO refactor this diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 0c9b5d70da..f09a97d0b9 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -381,38 +381,36 @@ def to_abi_arg(self, name: str = "") -> dict: components = [t.to_abi_arg(name=k) for k, t in self.member_types.items()] return {"name": name, "type": "tuple", "components": components} - # TODO breaking change: use kwargs instead of dict - # when using the type itself (not an instance) in the call position - # maybe rename to _ctor_call_return def _ctor_call_return(self, node: vy_ast.Call) -> "StructT": - validate_call_args(node, 1) - if not isinstance(node.args[0], vy_ast.Dict): + if len(node.args) > 0: raise VariableDeclarationException( - "Struct values must be declared via dictionary", node.args[0] + "Struct values must be declared as kwargs e.g. Foo(a=1, b=2)", node.args[0] ) if next((i for i in self.member_types.values() if isinstance(i, HashMapT)), False): raise VariableDeclarationException( "Struct contains a mapping and so cannot be declared as a literal", node ) + # manually validate kwargs for better error messages instead of + # relying on `validate_call_args` members = self.member_types.copy() keys = list(self.member_types.keys()) - for i, (key, value) in enumerate(zip(node.args[0].keys, node.args[0].values)): - if key is None or key.get("id") not in members: - hint = get_levenshtein_error_suggestions(key.get("id"), members, 1.0) - raise UnknownAttribute( - "Unknown or duplicate struct member.", key or value, hint=hint - ) - expected_key = keys[i] - if key.id != expected_key: + for i, kwarg in enumerate(node.keywords): + # x=5 => kwarg(arg="x", value=Int(5)) + argname = kwarg.arg + if argname not in members: + hint = get_levenshtein_error_suggestions(argname, members, 1.0) + raise UnknownAttribute("Unknown or duplicate struct member.", kwarg, hint=hint) + expected = keys[i] + if argname != expected: raise InvalidAttribute( "Struct keys are required to be in order, but got " - f"`{key.id}` instead of `{expected_key}`. (Reminder: the " + f"`{argname}` instead of `{expected}`. (Reminder: the " f"keys in this struct are {list(self.member_types.items())})", - key, + kwarg, ) - - validate_expected_type(value, members.pop(key.id)) + expected_type = members.pop(argname) + validate_expected_type(kwarg.value, expected_type) if members: raise VariableDeclarationException( @@ -422,4 +420,4 @@ def _ctor_call_return(self, node: vy_ast.Call) -> "StructT": return self def _ctor_modifiability_for_call(self, node: vy_ast.Call, modifiability: Modifiability) -> bool: - return all(check_modifiability(v, modifiability) for v in node.args[0].values) + return all(check_modifiability(k.value, modifiability) for k in node.keywords)