python / python/cpython

Cannot patch __call__ on an object with vectorcall defined

Open
#101,497 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-C-API type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

It appears that when the type of an object has JAX_TPFLAGS_HAVE_VECTORCALL set on tp_flags, then overrides to call from within python are ignored.

I encountered this bug when using the latest version of JAX, which introduced vectorcalls in https://github.com/tensorflow/tensorflow/commit/bf3eb110f49fe9628a31d8e2052951cd6d0082f0 :

import jax
g = jax.jit(lambda x: x + 1)
print(type(g))
# > <class 'google3.third_party.tensorflow.compiler.xla.python.xla_extension.CompiledFunction'>
print(g(5))
# > 6
type(g).__call__ = lambda *args: 0
print(g(5))
# > 6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the JAX example, then read Objects/call.c around the PyObject_Call vectorcall check and Include/internal/pycore_call.h around vectorcall dispatch. Determine the expected interaction with a Python-level call override and add regression coverage showing the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.