Skip to content

VIP: Temporarily remove type units #1881

@iamdefinitelyahuman

Description

@iamdefinitelyahuman

Simple Summary

The current implementation of type units feels inconsistent and confusing. I would like to remove them from the language in their current form.

Motivation

While working on type checking I keep running into issues with units. All of this is made much more difficult because there is very minimal documentation on the subject.

  1. uint256 is considered "unitless", so assignments such as uint256(wei) = uint256 are permitted. It took me a while to realize this was the case, I assumed uint256 was equivalent to uint256(None) and so should not be compatible with uint256(wei).
  2. Addition and subtraction between values with different units is disallowed, but multiplication and division is allowed and produces new compound unit types. This is completely undocumented and does not feel intuitive to me.
  3. wei_value and uint256(wei), despite both being uint256 with unit wei, are incompatible.
  4. Same for timestamp, timedelta, and uint256(sec). Per the documentation, timestamp additionally cannot be added or subtracted with another timestamp. I was unable to check with this firsthand, as attempting to assign to timestamp or timedelta gives me a TypeMistmatch. These feel broken.

While I'm not inherently opposed to the idea of units, the current implementation feels more confusing than beneficial. I propose we remove units altogether while refactoring. We can revisit the concept once refactoring is complete and documentation is up-to-date, and hopefully come up with another approach that's cleaner and more consistent.

Backwards Compatibility

It's a breaking change.

Copyright

Copyright and related rights waived via CC0

Metadata

Metadata

Assignees

No one assigned

    Labels

    VIP: DiscussionUsed to denote VIPs and more complex issues that are waiting discussion in a meeting

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions