This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: inspect and class methods
Type: behavior Stage:
Components: Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Yury.Selivanov, larry, skrah, yselivanov
Priority: normal Keywords:

Created on 2014-04-30 12:22 by skrah, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg217606 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-04-30 12:22
In Python2.7, the cls parameter shows up in pydoc:

    frombuf(cls, buf) from __builtin__.type
        Construct a TarInfo object from a 512 byte string buffer.


In 3.5, it doesn't:

    frombuf(buf, encoding, errors) from builtins.type
        Construct a TarInfo object from a 512 byte bytes object.



inspect.signature shows 'self', but not 'cls':

>>> from tarfile import *
>>> from inspect import *
>>> signature(TarInfo.create_gnu_header)
<Signature at 0x7f50cf110cf0 "(self, info, encoding, errors)">
>>> signature(TarInfo.frombuf)
<Signature at 0x7f50cf11cc88 "(buf, encoding, errors)">


So my guess is that this is an oversight.  How about the C docstrings?
Can we get "$cls" for classmethods?
msg217628 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-04-30 16:40
> In Python2.7, the cls parameter shows up in pydoc:
>
>    frombuf(cls, buf) from __builtin__.type
>        Construct a TarInfo object from a 512 byte string buffer.
>
>
> In 3.5, it doesn't:
>
>    frombuf(buf, encoding, errors) from builtins.type
>        Construct a TarInfo object from a 512 byte bytes object.

Yes, that's a correct behaviour in 3.4 and 3.5. See #20710 for details.

> >>> signature(TarInfo.create_gnu_header)
> <Signature at 0x7f50cf110cf0 "(self, info, encoding, errors)">
> >>> signature(TarInfo.frombuf)
> <Signature at 0x7f50cf11cc88 "(buf, encoding, errors)">

There is no bug here. `TarInfo.create_gnu_header` is an unbound method, that indeed requires first argument 'self'.  `TarInfo.frombuf` is a classmethod, so it doesn't need a 'cls' arg.  Signature, by default and by design, only shows arguments that need to be passed to correctly execute the given callable.

> How about the C docstrings? Can we get "$cls" for classmethods?

Yes, I think it should work.
msg217698 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-05-01 14:19
Okay, thanks.  I've used "$cls" for Decimal.from_float in 40b06a75d1c6,
and it appears to work already.


Feel free to close the issue (I don't know whether AC emits "$cls" or
if it should).
msg217726 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2014-05-01 21:14
Yeah, I'm closing this issue.
msg217736 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-05-02 00:14
By default AC emits "$type" for class methods, see dict_fromkeys in Objects/dictobject.c.
msg217750 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-05-02 12:38
> By default AC emits "$type" for class methods, see dict_fromkeys in Objects/dictobject.c.

Thanks, good choice.
History
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65598
2014-05-02 12:38:42skrahsetmessages: + msg217750
2014-05-02 00:14:49larrysetmessages: + msg217736
2014-05-01 21:14:51yselivanovsetstatus: open -> closed
resolution: not a bug
messages: + msg217726
2014-05-01 14:19:45skrahsetmessages: + msg217698
2014-04-30 16:40:58yselivanovsetnosy: + yselivanov
messages: + msg217628
2014-04-30 12:22:03skrahcreate