Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.17 KB

File metadata and controls

49 lines (40 loc) · 1.17 KB

Static Python

A subset of Python that transpiles to compiled languages.

Rules

  • Use fixed-width integers: i32, u64, etc.
  • Use decorators and composition instead of inheritance
  • Use Result[T, E] instead of exceptions
  • Use match as an expression. Note that there is no case keyword.
    match x:
        1: ...
        2: ...
    
  • match can be nested inside other matches to write succinct code
  • Elide types when easily inferred
  • Always specify return types on functions
  • Use design by contract with smt.pre and smt.post

Example

def classify_triangle(a: int, b: int, c: int) -> TriangleType:
    if smt.pre:
        assert a > 0
        assert b > 0
        assert c > 0
        assert a < (b + c)
        assert b < (a + c)
        assert c < (a + b)

    if a == b == c:
        result = TriangleType.EQUILATERAL
    elif a == b or b == c or a == c:
        result = TriangleType.ISOSCELES
    else:
        result = TriangleType.SCALENE

    if smt_post:
        assert smt.post(result)

    return result

Reference

Unsupported features Verification Decorators