Skip to content

Commit 44718b8

Browse files
committed
Fix the int.__pow__ plugin
A recent typeshed change added a modulo argument to int.__pow__ which broke the plugin. Tested manually. I didn't add a test because to be useful it would need to be a cmdline test (so it uses the real typeshed) and this doesn't seem worth adding a slow cmdline test for. Happy to add it if someone disagrees though. Fixes #7621.
1 parent 8f381b8 commit 44718b8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mypy/plugins/default.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,10 @@ def typed_dict_update_signature_callback(ctx: MethodSigContext) -> CallableType:
365365

366366
def int_pow_callback(ctx: MethodContext) -> Type:
367367
"""Infer a more precise return type for int.__pow__."""
368-
if (len(ctx.arg_types) == 1
369-
and len(ctx.arg_types[0]) == 1):
368+
# int.__pow__ has an optional modulo argument,
369+
# so we expect 2 argument positions
370+
if (len(ctx.arg_types) == 2
371+
and len(ctx.arg_types[0]) == 1 and len(ctx.arg_types[1]) == 0):
370372
arg = ctx.args[0][0]
371373
if isinstance(arg, IntExpr):
372374
exponent = arg.value

0 commit comments

Comments
 (0)