Skip to content

Commit 9eea485

Browse files
committed
add examples for return annotations
1 parent 5808907 commit 9eea485

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

example/example.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ def func_a():
77
def func_b(arg1):
88
pass
99

10-
def func_c(arg1, arg2):
10+
def func_c(arg1, arg2) -> None:
1111
pass
1212

13-
def func_d(arg1, arg2, arg3):
13+
def func_d(arg1, arg2, arg3) -> int:
1414
pass
1515

16-
def func_e(arg1, arg2, arg3, arg4):
16+
def func_e(arg1, arg2, arg3, arg4) -> str:
1717
pass
1818

19-
def func_f(arg1, arg2: int, arg3, arg4, arg5: int=123):
19+
def func_f(arg1, arg2: int, arg3, arg4, arg5: int=123) -> bytes:
2020
pass
2121

2222
def func_g(arg1, arg2, arg3: str='test', arg4=None):
@@ -40,16 +40,16 @@ def func_a(self):
4040
def func_b(self, arg1):
4141
pass
4242

43-
def func_c(self, arg1, arg2):
43+
def func_c(self, arg1, arg2) -> None:
4444
pass
4545

46-
def func_d(self, arg1, arg2, arg3):
46+
def func_d(self, arg1, arg2, arg3) -> int:
4747
pass
4848

49-
def func_e(self, arg1, arg2, arg3, arg4):
49+
def func_e(self, arg1, arg2, arg3, arg4) -> str:
5050
pass
5151

52-
def func_f(self, arg1, arg2: int, arg3, arg4, arg5: int=123):
52+
def func_f(self, arg1, arg2: int, arg3, arg4, arg5: int=123) -> bytes:
5353
pass
5454

5555
def func_g(self, arg1, arg2, arg3: str='test', arg4=None):

example/modexample.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,63 @@
3434

3535
#if MICROPY_PY_EXAMPLE
3636

37-
// def func_a():
37+
// def func_a()
3838
STATIC mp_obj_t mod_example_func_a(void) {
3939
// TODO
4040
return mp_const_none;
4141
}
4242
MP_DEFINE_CONST_FUN_OBJ_0(mod_example_func_a_obj, mod_example_func_a);
4343

44-
// def func_b(arg1):
44+
// def func_b(arg1)
4545
STATIC mp_obj_t mod_example_func_b(mp_obj_t arg1) {
4646
// TODO
4747
return mp_const_none;
4848
}
4949
MP_DEFINE_CONST_FUN_OBJ_1(mod_example_func_b_obj, mod_example_func_b);
5050

51-
// def func_c(arg1, arg2):
51+
// def func_c(arg1, arg2) -> None
5252
STATIC mp_obj_t mod_example_func_c(mp_obj_t arg1, mp_obj_t arg2) {
5353
// TODO
5454
return mp_const_none;
5555
}
5656
MP_DEFINE_CONST_FUN_OBJ_2(mod_example_func_c_obj, mod_example_func_c);
5757

58-
// def func_d(arg1, arg2, arg3):
58+
// def func_d(arg1, arg2, arg3) -> int
5959
STATIC mp_obj_t mod_example_func_d(mp_obj_t arg1, mp_obj_t arg2, mp_obj_t arg3) {
6060
// TODO
6161
return mp_const_none;
6262
}
6363
MP_DEFINE_CONST_FUN_OBJ_3(mod_example_func_d_obj, mod_example_func_d);
6464

65-
// def func_e(arg1, arg2, arg3, arg4):
65+
// def func_e(arg1, arg2, arg3, arg4) -> str
6666
STATIC mp_obj_t mod_example_func_e(size_t n_args, const mp_obj_t *args) {
6767
// TODO
6868
return mp_const_none;
6969
}
7070
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_e_obj, 4, 4, mod_example_func_e);
7171

72-
// def func_f(arg1, arg2: int, arg3, arg4, arg5: int=123):
72+
// def func_f(arg1, arg2: int, arg3, arg4, arg5: int=123) -> bytes
7373
STATIC mp_obj_t mod_example_func_f(size_t n_args, const mp_obj_t *args) {
7474
// TODO
7575
return mp_const_none;
7676
}
7777
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_f_obj, 4, 5, mod_example_func_f);
7878

79-
// def func_g(arg1, arg2, arg3: str='test', arg4=None):
79+
// def func_g(arg1, arg2, arg3: str='test', arg4=None)
8080
STATIC mp_obj_t mod_example_func_g(size_t n_args, const mp_obj_t *args) {
8181
// TODO
8282
return mp_const_none;
8383
}
8484
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_func_g_obj, 2, 4, mod_example_func_g);
8585

86-
// def func_h(arg1, arg2, arg3, *args):
86+
// def func_h(arg1, arg2, arg3, *args)
8787
STATIC mp_obj_t mod_example_func_h(size_t n_args, const mp_obj_t *args) {
8888
// TODO
8989
return mp_const_none;
9090
}
9191
MP_DEFINE_CONST_FUN_OBJ_VAR(mod_example_func_h_obj, 3, mod_example_func_h);
9292

93-
// def func_i(arg1, arg2, **kwargs):
93+
// def func_i(arg1, arg2, **kwargs)
9494
STATIC mp_obj_t mod_example_func_i(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
9595
// TODO
9696
return mp_const_none;
@@ -102,70 +102,70 @@ typedef struct _mp_obj_Class_t {
102102
mp_obj_base_t base;
103103
} mp_obj_Class_t;
104104

105-
// def Class.__init__(self, arg1, arg2):
105+
// def Class.__init__(self, arg1, arg2)
106106
STATIC mp_obj_t mod_example_Class_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
107107
mp_obj_Class_t *o = m_new_obj(mp_obj_Class_t);
108108
o->base.type = type;
109109
return MP_OBJ_FROM_PTR(o);
110110
}
111111

112-
// def Class.func_a(self):
112+
// def Class.func_a(self)
113113
STATIC mp_obj_t mod_example_Class_func_a(mp_obj_t self) {
114114
// TODO
115115
return mp_const_none;
116116
}
117117
MP_DEFINE_CONST_FUN_OBJ_1(mod_example_Class_func_a_obj, mod_example_Class_func_a);
118118

119-
// def Class.func_b(self, arg1):
119+
// def Class.func_b(self, arg1)
120120
STATIC mp_obj_t mod_example_Class_func_b(mp_obj_t self, mp_obj_t arg1) {
121121
// TODO
122122
return mp_const_none;
123123
}
124124
MP_DEFINE_CONST_FUN_OBJ_2(mod_example_Class_func_b_obj, mod_example_Class_func_b);
125125

126-
// def Class.func_c(self, arg1, arg2):
126+
// def Class.func_c(self, arg1, arg2) -> None
127127
STATIC mp_obj_t mod_example_Class_func_c(mp_obj_t self, mp_obj_t arg1, mp_obj_t arg2) {
128128
// TODO
129129
return mp_const_none;
130130
}
131131
MP_DEFINE_CONST_FUN_OBJ_3(mod_example_Class_func_c_obj, mod_example_Class_func_c);
132132

133-
// def Class.func_d(self, arg1, arg2, arg3):
133+
// def Class.func_d(self, arg1, arg2, arg3) -> int
134134
STATIC mp_obj_t mod_example_Class_func_d(size_t n_args, const mp_obj_t *args) {
135135
// TODO
136136
return mp_const_none;
137137
}
138138
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Class_func_d_obj, 4, 4, mod_example_Class_func_d);
139139

140-
// def Class.func_e(self, arg1, arg2, arg3, arg4):
140+
// def Class.func_e(self, arg1, arg2, arg3, arg4) -> str
141141
STATIC mp_obj_t mod_example_Class_func_e(size_t n_args, const mp_obj_t *args) {
142142
// TODO
143143
return mp_const_none;
144144
}
145145
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Class_func_e_obj, 5, 5, mod_example_Class_func_e);
146146

147-
// def Class.func_f(self, arg1, arg2: int, arg3, arg4, arg5: int=123):
147+
// def Class.func_f(self, arg1, arg2: int, arg3, arg4, arg5: int=123) -> bytes
148148
STATIC mp_obj_t mod_example_Class_func_f(size_t n_args, const mp_obj_t *args) {
149149
// TODO
150150
return mp_const_none;
151151
}
152152
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Class_func_f_obj, 5, 6, mod_example_Class_func_f);
153153

154-
// def Class.func_g(self, arg1, arg2, arg3: str='test', arg4=None):
154+
// def Class.func_g(self, arg1, arg2, arg3: str='test', arg4=None)
155155
STATIC mp_obj_t mod_example_Class_func_g(size_t n_args, const mp_obj_t *args) {
156156
// TODO
157157
return mp_const_none;
158158
}
159159
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_example_Class_func_g_obj, 3, 5, mod_example_Class_func_g);
160160

161-
// def Class.func_h(self, arg1, arg2, arg3, *args):
161+
// def Class.func_h(self, arg1, arg2, arg3, *args)
162162
STATIC mp_obj_t mod_example_Class_func_h(size_t n_args, const mp_obj_t *args) {
163163
// TODO
164164
return mp_const_none;
165165
}
166166
MP_DEFINE_CONST_FUN_OBJ_VAR(mod_example_Class_func_h_obj, 4, mod_example_Class_func_h);
167167

168-
// def Class.func_i(self, arg1, arg2, **kwargs):
168+
// def Class.func_i(self, arg1, arg2, **kwargs)
169169
STATIC mp_obj_t mod_example_Class_func_i(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
170170
// TODO
171171
return mp_const_none;

extmod-generator

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ class Function(object):
7676
args.append('**kwargs')
7777
p = 'def {name}({args})'.format(name=self.dotname, args=', '.join(args))
7878
if 'return' in self.argspec.annotations:
79-
p += ' -> {ret}:'.format(ret=anot('return'))
80-
else:
81-
p += ':'
79+
p += ' -> {ret}'.format(ret=anot('return'))
8280
return p
8381

8482
class Class(object):

0 commit comments

Comments
 (0)