-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnone.py
42 lines (33 loc) · 1.46 KB
/
none.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
import typing
from collections.abc import Sequence
import mypy.nodes
from puya.awst.nodes import Expression, VoidConstant
from puya.errors import CodeError
from puya.parse import SourceLocation
from puyapy.awst_build import pytypes
from puyapy.awst_build.eb import _expect as expect
from puyapy.awst_build.eb._base import NotIterableInstanceExpressionBuilder
from puyapy.awst_build.eb._utils import constant_bool_and_error
from puyapy.awst_build.eb.interface import InstanceBuilder, NodeBuilder, TypeBuilder
class NoneTypeBuilder(TypeBuilder):
def __init__(self, location: SourceLocation):
super().__init__(pytypes.NoneType, location)
@typing.override
def call(
self,
args: Sequence[NodeBuilder],
arg_kinds: list[mypy.nodes.ArgKind],
arg_names: list[str | None],
location: SourceLocation,
) -> InstanceBuilder:
expect.no_args(args, location)
return NoneExpressionBuilder(VoidConstant(location))
class NoneExpressionBuilder(NotIterableInstanceExpressionBuilder):
def __init__(self, expr: Expression):
super().__init__(pytypes.NoneType, expr)
@typing.override
def to_bytes(self, location: SourceLocation) -> Expression:
raise CodeError("None is not usable as a value", location)
@typing.override
def bool_eval(self, location: SourceLocation, *, negate: bool = False) -> InstanceBuilder:
return constant_bool_and_error(value=False, location=location, negate=negate)