Skip to content

Commit 877974e

Browse files
committed
[mypyc] Support ellipsis (...) expressions in class bodies
This can be used to declare concise custom exceptions, e.g. class UnknownReleaseError(ValueError): ... which otherwise probably would be written class UnknownReleaseError(ValueError): pass and is supported by CPython. Closes mypyc/mypyc#1069
1 parent 46c108e commit 877974e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mypyc/irbuild/classdef.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CallExpr,
1313
ClassDef,
1414
Decorator,
15+
EllipsisExpr,
1516
ExpressionStmt,
1617
FuncDef,
1718
Lvalue,
@@ -145,7 +146,11 @@ def transform_class_def(builder: IRBuilder, cdef: ClassDef) -> None:
145146
continue
146147
with builder.catch_errors(stmt.line):
147148
cls_builder.add_method(get_func_def(stmt))
148-
elif isinstance(stmt, PassStmt):
149+
elif (
150+
isinstance(stmt, PassStmt)
151+
or isinstance(stmt, ExpressionStmt)
152+
and isinstance(stmt.expr, EllipsisExpr)
153+
):
149154
continue
150155
elif isinstance(stmt, AssignmentStmt):
151156
if len(stmt.lvalues) != 1:

0 commit comments

Comments
 (0)