From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.bugs Subject: bug#45348: 27.1; python-eldoc-setup-code uses obsolete python function Date: Thu, 24 Dec 2020 00:53:38 +0100 Message-ID: <877dp8dqpp.fsf@posteo.net> References: <197a8432-07fd-4639-e504-0fde30d3f088@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32211"; mail-complaints-to="usenet@ciao.gmane.io" To: Steven De Herdt , 45348@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 24 00:54:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksDxM-0008Gb-4e for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Dec 2020 00:54:12 +0100 Original-Received: from localhost ([::1]:49118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksDxK-0007aL-TZ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 23 Dec 2020 18:54:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksDxD-0007Zz-CU for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 18:54:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ksDxC-0002rg-39 for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 18:54:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ksDxC-0007tE-0a for bug-gnu-emacs@gnu.org; Wed, 23 Dec 2020 18:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tomas Nordin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 23 Dec 2020 23:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45348 X-GNU-PR-Package: emacs Original-Received: via spool by 45348-submit@debbugs.gnu.org id=B45348.160876763030311 (code B ref 45348); Wed, 23 Dec 2020 23:54:01 +0000 Original-Received: (at 45348) by debbugs.gnu.org; 23 Dec 2020 23:53:50 +0000 Original-Received: from localhost ([127.0.0.1]:54395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksDwz-0007sn-Ok for submit@debbugs.gnu.org; Wed, 23 Dec 2020 18:53:50 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:43945) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksDww-0007sT-8q for 45348@debbugs.gnu.org; Wed, 23 Dec 2020 18:53:47 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 92A0A2400FB for <45348@debbugs.gnu.org>; Thu, 24 Dec 2020 00:53:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1608767619; bh=nHkhR7bIUtpD5pKOlucvjUhB1/1aZCC3R6+B6BxPe0o=; h=From:To:Subject:Date:From; b=Xkq2cwBIkg/8cwxoAgp49hpp4ky0vjq7IfkPMZSU6M3p+hw5bSWqrvBLvQ5s3nc+r fnsgnZT3UnZd9X2MvtY03SSWzG5Ikkc8VbxR51GZRk22+Xr0nJr/kshAzpjNBBsIax DHpKQINWX7n9WrE8bC924hnjn902+Lo0J7s0R+hZ5276V3lkGeVugsd6C14VLAPEqz ZzmoMziJYiuWapBBYXPI3p8KNY9N8jt7jOtPRJVPnqPTDI77OMSkIN+J3AS6sNmSvu np54DWiK0XMLabiuOGYOuYYaQVDzANmCFqR62CDqF6yeKJFUsuBCgWwkfEWneLI+t9 zVn0sONG/48hg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D1VQp6CXbz9rxP; Thu, 24 Dec 2020 00:53:38 +0100 (CET) In-Reply-To: <197a8432-07fd-4639-e504-0fde30d3f088@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196645 Archived-At: --=-=-= Content-Type: text/plain Steven De Herdt writes: > Hello folks > > This report concerns eldoc for Python. I'm using Debian testing, with > Python 3.9, in my daily config I use ipython3 as > python-shell-interpreter. Every time I place point in the argument list > of a Python function without documentation, the minibuffer expands to > show a warning ("DeprecationWarning: `formatargspec` is deprecated since > Python 3.5. Use `signature` and the `Signature` object directly"), an > unrelated snippet of my code, as well as the intended function signature. > > This behaviour can be partly reproduced in a minimal setting with the > attached func.py: > * emacs -Q func.py > * C-u C-c C-p , choose "python3 -i" > * in buffer for func.py: C-c C-c > * place point at argument (13) of the call to func > The DeprecationWarning only shows the first time with python3. My > ipython3 shows it every time however, that's a bit annoying. I'm not > sure the repeated warning is an issue with ipython, but the eldoc setup > code would need to upgrade from deprecated functionality anyway. I can reproduce this with Python 3.7.3 on Debian stable. And yes, strange behaviour with Ipython, which is maybe not about the eldoc setup code. > Maybe I'll try to make python-eldoc-setup-code use inspect.signature if > it annoys me too much. :) Yes, did you figure out something safe and sound? Otherwise can you please try the attached patch. It fixes the problem here. The patch touch the string of python code `python-eldoc-setup-code' and do a little more than simply not call formatargspec with python 3, but does not change the intended effect. I think the patch improves readability somewhat. But also I identified a few bugs with the python code in the string. Those bugs doesn't surface due to the (needed) wrapping try block. Here are the observed bugs, - if obj is not a string, if isinstance(obj, str_type) fails and doc does not get defined. After this, doc is referred to in the next test, (if not doc and callable(obj):) which will then error. - if obj is a class instance and has an empty docstring and is not callable (often not), then (if not doc and callable(obj)) fails and doc.splitlines()[0] will Error. - again, if obj is a class instance, not callable but has no docstring, doc will be None and doc.splitlines() will error. - if obj is provided as the object itself, the function always fail because doc does not get defined. Those bugs are fixed with the patch, as well as using inspect.signature with python 3 as recommended by the deprecation warning. Besides the patch, I wonder what other users thinks about the resulting behaviour of this python function. Here is a a suitable docstring for `python-eldoc-setup-code', would it be provided: """Provide a docstring or signature on obj. Prefer a docstring, and fall back on the signature if no docstring is found.""" Meaning, if there is a docstring, we will not get the call signature, we get that only when there is no docstring. Personally I would prefer the call signature always, like in elisp. Then perhaps when doing C-c C-f (python-eldoc-at-point) show the (full) docstring. But that would be another bug-report I guess. Best regards -- Tomas --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=pydoc-45348.patch diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d58b32f3c3..6acfafdb68 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4533,33 +4533,35 @@ python-eldoc-setup-code "def __PYDOC_get_help(obj): try: import inspect + from sys import version_info as version_info + try: - str_type = basestring - argspec_function = inspect.getargspec - except NameError: - str_type = str - argspec_function = inspect.getfullargspec - if isinstance(obj, str_type): obj = eval(obj, globals()) - doc = inspect.getdoc(obj) + doc = inspect.getdoc(obj) + except TypeError: + doc = inspect.getdoc(obj) + if not doc and callable(obj): - target = None if inspect.isclass(obj) and hasattr(obj, '__init__'): target = obj.__init__ objtype = 'class' else: target = obj objtype = 'def' - if target: - args = inspect.formatargspec(*argspec_function(target)) - name = obj.__name__ - doc = '{objtype} {name}{args}'.format( - objtype=objtype, name=name, args=args - ) - else: + if version_info.major == 3: + args = str(inspect.signature(target)) + else: + args = inspect.formatargspec(*inspect.getargspec(target)) + + name = obj.__name__ + doc = '{objtype} {name}{args}'.format( + objtype=objtype, name=name, args=args) + elif doc: doc = doc.splitlines()[0] + else: + doc = '' except: - doc = '' + return '' return doc" "Python code to setup documentation retrieval." :type 'string --=-=-=--