Skip to content

Commit 725145e

Browse files
authored
[mypyc] Fixing condition to fall back to PyCall for staticmethod and classmethod (#18228)
Fixes mypyc/mypyc#1076 This change has been copied from [mypyc/irbuild/builder.py#1084](https://github.com/advait-dixit/mypy/blob/1a9596453bf6377b8fee822cf0bf74350993ec28/mypyc/irbuild/builder.py#L1084).
1 parent 1a95964 commit 725145e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

mypyc/irbuild/expression.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Callable, Sequence
1111

1212
from mypy.nodes import (
13+
ARG_NAMED,
1314
ARG_POS,
1415
LDEF,
1516
AssertTypeExpr,
@@ -355,6 +356,7 @@ def translate_method_call(builder: IRBuilder, expr: CallExpr, callee: MemberExpr
355356
and isinstance(callee.expr.node, TypeInfo)
356357
and callee.expr.node in builder.mapper.type_to_ir
357358
and builder.mapper.type_to_ir[callee.expr.node].has_method(callee.name)
359+
and all(kind in (ARG_POS, ARG_NAMED) for kind in expr.arg_kinds)
358360
):
359361
# Call a method via the *class*
360362
assert isinstance(callee.expr.node, TypeInfo)

mypyc/test-data/run-classes.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,3 +2631,27 @@ print(f'{Player.MIN = }')
26312631
from native import Player
26322632
[out]
26332633
Player.MIN = <Player.MIN: 1>
2634+
2635+
[case testStaticCallsWithUnpackingArgs]
2636+
from typing import Tuple
2637+
2638+
class Foo:
2639+
@staticmethod
2640+
def static(a: int, b: int, c: int) -> Tuple[int, int, int]:
2641+
return (c+1, a+2, b+3)
2642+
2643+
@classmethod
2644+
def clsmethod(cls, a: int, b: int, c: int) -> Tuple[int, int, int]:
2645+
return (c+1, a+2, b+3)
2646+
2647+
2648+
print(Foo.static(*[10, 20, 30]))
2649+
print(Foo.static(*(40, 50), *[60]))
2650+
assert Foo.static(70, 80, *[90]) == Foo.clsmethod(70, *(80, 90))
2651+
2652+
[file driver.py]
2653+
import native
2654+
2655+
[out]
2656+
(31, 12, 23)
2657+
(61, 42, 53)

0 commit comments

Comments
 (0)