@@ -137,27 +137,28 @@ def get_mypyc_attrs(
137
137
attrs : MypycAttrs = {}
138
138
lines : dict [MypycAttr , int ] = {}
139
139
140
- def record_unsupported_key (key : str ) -> None :
141
- errors .error (f"{ key } is not a supported `mypyc_attrs` key." , path , line )
142
- errors .note (f"supported keys: { ', ' .join (map (repr , sorted (MYPYC_ATTRS )))} " , path , line )
140
+ def set_mypyc_attr (key : MypycAttr , value : Any , line : int ) -> None :
141
+ if key in MYPYC_ATTRS :
142
+ attrs [key ] = value
143
+ lines [key ] = line
144
+ else :
145
+ errors .error (f"{ key } is not a supported `mypyc_attrs` key." , path , line )
146
+ errors .note (f"supported keys: { ', ' .join (map (repr , sorted (MYPYC_ATTRS )))} " , path , line )
143
147
144
148
for dec in stmt .decorators :
145
149
if d := get_mypyc_attr_call (dec ):
146
150
line = d .line
151
+
152
+ key : MypycAttr
147
153
for name , arg in zip (d .arg_names , d .args ):
148
154
if name is None :
149
155
if isinstance (arg , StrExpr ):
150
- key = cast (MypycAttr , arg .value )
151
- if key in MYPYC_ATTRS :
152
- attrs [key ] = True
153
- lines [key ] = line
154
- else :
155
- record_unsupported_key (key )
156
- elif name not in MYPYC_ATTRS :
157
- record_unsupported_key (name )
156
+ set_mypyc_attr (arg .value , True , line )
157
+ else :
158
+ errors .error ("All `mypyc_attr` positional arguments must be string literals." , path , line )
158
159
else :
159
- attrs [ name ] = get_mypyc_attr_literal (arg )
160
- lines [ name ] = line
160
+ arg_value = get_mypyc_attr_literal (arg )
161
+ set_mypyc_attr ( name , arg_value , line )
161
162
162
163
return attrs , lines
163
164
0 commit comments