Skip to content

VIP: Change Mapping Syntax (again) #1969

@fubuloubu

Description

@fubuloubu

Simple Summary

Change mapping syntax from var: map(key_type, val_type) to var: HashMap[key_type, val_type]

Motivation

Mapping syntax was changed in #564. While it made for easier understanding of how mappings work in practice, it precludes the use of the Python standard function map(fn, iter) -> iter for anything in Vyper to use. We propose adopting a MyPy-like type structure, which will make working with mappings (and nested mappings) more apparent, and open up the keyword map to future use as an iterator operation.

Specification

The syntax for mappings would change from var: map(key_type, val_type) to var: HashMap[key_type, val_type]. This looks like the following in practice:

struct MyStruct: ...

my_mapping: HashMap[uint256, MyStruct]

my_nested_map: HashMap[bytes32, HashMap[uint256, address]]

@public
def foo():
    self.my_mapping[1] = MyStruct({...})  # Same access as before
    self.my_nested_map[blk.hash][1] = msg.sender  # Same access as before

Backwards Compatibility

This VIP will break the current syntax for defining mappings

Dependencies

Depends on #564

References

No references

Copyright

Copyright and related rights waived via CC0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions