Skip to content

Commit 89b360c

Browse files
earlbreaddahlia
authored andcommitted
Add numeric-constraints annotation docs
1 parent 7ff8206 commit 89b360c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/annotation.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,32 @@ class FileNotFound(FileError):
129129
class FileNotReadable(FileError):
130130
...
131131
~~~~~~~~
132+
133+
### `@numeric-constraints` {#numeric-constraints}
134+
135+
`@numeric-constraints` annotation constrain the range of the input value.
136+
Currently, available annotation arguments are below:
137+
138+
`min`: Minimum input value; inclusive
139+
140+
`max`: Maximum input value; inclusive
141+
142+
For example, the following first Nirum code is compiled to the second Python
143+
code:
144+
145+
~~~~~~~~ nirum
146+
@numeric-constraints(min=1, max=12)
147+
unboxed month (int32);
148+
~~~~~~~~
149+
150+
~~~~~~~~ python
151+
class Month(object):
152+
...
153+
def __init__(self, value: '__builtin__.int') -> None:
154+
...
155+
if not (value <= (12)):
156+
raise ValueError("value is greater than 12")
157+
if not (value >= (1)):
158+
raise ValueError("value is less than 1")
159+
...
160+
~~~~~~~~

0 commit comments

Comments
 (0)