Skip to content

Commit 94cf8dd

Browse files
committed
Change assertion to error
1 parent 8eac14e commit 94cf8dd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mypyc/irbuild/specialize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,10 @@ def translate_object_new(builder: IRBuilder, expr: CallExpr, callee: RefExpr) ->
10251025
f"{call} not supported for classes inheriting from non-native classes", expr.line
10261026
)
10271027
return None
1028+
if len(expr.args) != 1:
1029+
builder.error(f"{call} supported only with 1 argument, got {len(expr.args)}", expr.line)
1030+
return None
10281031

1029-
assert (
1030-
len(expr.args) == 1
1031-
), f"Expected object.__new__() call to have exactly 1 argument, got {len(expr.args)}"
10321032
typ_arg = expr.args[0]
10331033
method_args = fn.fitem.arg_names
10341034
if isinstance(typ_arg, NameExpr) and len(method_args) > 0 and method_args[0] == typ_arg.name:

mypyc/test-data/irbuild-classes.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,14 @@ class ClsListAssignment:
20522052
[cls, val] = [object, "object"] # E: Assignment to argument cls in __new__ method unsupported
20532053
return object.__new__(cls)
20542054

2055+
class WrongNumberOfArgs:
2056+
def __new__(cls):
2057+
return super().__new__() # E: object.__new__() supported only with 1 argument, got 0
2058+
2059+
class WrongNumberOfArgsObjectNew:
2060+
def __new__(cls):
2061+
return object.__new__(cls, 1) # E: object.__new__() supported only with 1 argument, got 2
2062+
20552063
[case testClassWithFreeList]
20562064
from mypy_extensions import mypyc_attr, trait
20572065

0 commit comments

Comments
 (0)