Skip to content

Commit c2f3d36

Browse files
Update util.py
1 parent 3c27112 commit c2f3d36

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

mypyc/irbuild/util.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,28 @@ def get_mypyc_attrs(
137137
attrs: MypycAttrs = {}
138138
lines: dict[MypycAttr, int] = {}
139139

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)
143147

144148
for dec in stmt.decorators:
145149
if d := get_mypyc_attr_call(dec):
146150
line = d.line
151+
152+
key: MypycAttr
147153
for name, arg in zip(d.arg_names, d.args):
148154
if name is None:
149155
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)
158159
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)
161162

162163
return attrs, lines
163164

0 commit comments

Comments
 (0)