[pypy-issue] Issue #2462: `__init__` inherited from object incorrectly considered method by `inspect` (pypy/pypy)

Unknown issues-reply at bitbucket.org
Wed Jan 4 05:00:37 EST 2017


New issue 2462: `__init__` inherited from object incorrectly considered method by `inspect`
https://bitbucket.org/pypy/pypy/issues/2462/__init__-inherited-from-object-incorrectly

Unknown:

To reproduce:

```
#!python
import inspect

class C(object):
    pass

assert not inspect.ismethod(C.__init__)
assert not inspect.isfunction(C.__init__)
```

The above succeeds with Python 2 and Python 3 (and with Jython and IronPython for that matter) but fails both with PyPy2 and PyPy3. This is a problem for code that uses introspection to see what arguments a class accepts. With PyPy it looks as if this `__init__` would accept arguments because it is method/function (depending on are we on PyPy2 or PyPy3, similarly as in Python itself) and `inspect.getargspec(C.__init__)` returns this:

    ArgSpec(args=['obj'], varargs='args', keywords='keywords', defaults=None)

With Python 2 and Python 3 what you get from `inspect.getargspec` depends on the version (Python 2 raises `TypeError` and Python 3 returns similar result as PyPy), but that doesn't matter because neither of them consider this `__init__` a method or a function in the first place.




More information about the pypy-issue mailing list