-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyping_plus.py
82 lines (56 loc) · 1.5 KB
/
typing_plus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from __future__ import annotations
from typing import *
# TODO: ": Self" typehints when we get it in 3.11
# (can't typehint : Number currently because Liskov)
class Number(Protocol):
@staticmethod
def zero() -> Number:
...
@staticmethod
def one() -> Number:
...
def __neg__(self) -> Number:
...
def __add__(self, other) -> Number:
...
def __sub__(self, other) -> Number:
...
def __mul__(self, other) -> Number:
...
def __pow__(self, power: int, modulo=None) -> Number:
...
def scalar_mult(self, k: int) -> Number:
...
class FiniteField(Number):
p: int
m: int
q: int
@staticmethod
def Generator():
...
class Int(Number):
v: int
def __init__(self, v):
self.v = v
@staticmethod
def zero() -> Int:
return Int(0)
@staticmethod
def one() -> Int:
return Int(1)
def __eq__(self, other) -> bool:
return self.v == other.v
def __neg__(self) -> Int:
return Int(-self.v)
def __add__(self, other) -> Int:
return Int(self.v + other.v)
def __sub__(self, other) -> Int:
return Int(self.v - other.v)
def __mul__(self, other) -> Int:
return Int(self.v * other.v)
def __pow__(self, power: int, modulo=None) -> Int:
return Int(pow(self.v, power, modulo))
def scalar_mult(self, k: int) -> Int:
return Int(k * self.v)
def __str__(self):
return str(self.v)