From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel Newsgroups: gmane.emacs.bugs Subject: bug#24401: python-shell-completion-native-try returns incorrect results with python 3.5.2 Date: Wed, 26 Oct 2016 23:35:57 -0400 Message-ID: <220cf6b0-de5c-7d4b-410e-97c0a37d768c@live.com> References: <1d47cad6-227f-280a-2645-d97b45bbda44@live.com> <184c70a4-edba-b253-8d7b-2c15d67dacfc@live.com> <3d4d75b1-3de1-4edb-abf3-2dd5b1f75e75@wh2.tu-dresden.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tD3t34prxlTrAjm0SogJ40STNHH19UsVx" X-Trace: blaine.gmane.org 1477539451 17693 195.159.176.226 (27 Oct 2016 03:37:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 27 Oct 2016 03:37:31 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 Cc: 24401@debbugs.gnu.org To: Lukas Juhrich , Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 27 05:37:27 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzbVC-0002W6-In for geb-bug-gnu-emacs@m.gmane.org; Thu, 27 Oct 2016 05:37:14 +0200 Original-Received: from localhost ([::1]:38699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzbVF-00059n-2o for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Oct 2016 23:37:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bzbV3-00058F-9s for bug-gnu-emacs@gnu.org; Wed, 26 Oct 2016 23:37:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bzbV0-0006mM-45 for bug-gnu-emacs@gnu.org; Wed, 26 Oct 2016 23:37:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bzbV0-0006m6-0C for bug-gnu-emacs@gnu.org; Wed, 26 Oct 2016 23:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bzbUz-0005cI-Mw for bug-gnu-emacs@gnu.org; Wed, 26 Oct 2016 23:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 Oct 2016 03:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24401 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24401-submit@debbugs.gnu.org id=B24401.147753938721545 (code B ref 24401); Thu, 27 Oct 2016 03:37:01 +0000 Original-Received: (at 24401) by debbugs.gnu.org; 27 Oct 2016 03:36:27 +0000 Original-Received: from localhost ([127.0.0.1]:58770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzbUR-0005bR-9V for submit@debbugs.gnu.org; Wed, 26 Oct 2016 23:36:27 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.130]:54435) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzbUP-0005bE-5y for 24401@debbugs.gnu.org; Wed, 26 Oct 2016 23:36:25 -0400 Original-Received: from [18.189.21.121] ([18.189.21.121]) by mrelayeu.kundenserver.de (mreue001) with ESMTPSA (Nemesis) id 0Lg9rw-1ceNoO1MMG-00nfdR; Thu, 27 Oct 2016 05:36:04 +0200 In-Reply-To: <3d4d75b1-3de1-4edb-abf3-2dd5b1f75e75@wh2.tu-dresden.de> X-Provags-ID: V03:K0:pkQly5iWHop27ywvRUKRfpQb5YLkE2NMfVNgowcI0KzNx9SfU+y 5MH6wJ7i9Q9Heup0cqJS2OHgNlgERdvhNqH/AZm7tXoVoawy2EldGfaYX2WIGcCabMEExcs VUcv5raladvdwkqgg9KqFQ4vwVg23eJxvmtEWyW/kiZYcRQIiClMbToribxeJSYm+MlUDkx 5/7Y30FwPj/7t/oMbeC2g== X-UI-Out-Filterresults: notjunk:1;V01:K0:dVjzzhPPchA=:rgL/WwqdahXsNZNQt9BCtP 5KbWgFDcHoLLZnqkyVJ/CuZ6+y4kMBa5s0QBXI54RBLKcUP7UukcmkOBYcAJcHTiBPb7mlSnn 8ICkqeeX5S+LxDdD2qP8r8xgoMrRzAAI0N62rP61yiw/Mu7JDBJRg/pTCZMfN0MdNE3xED7iA syszR4JbvVsaR7JD32uFhCexmaHxgAtzqcG1LC/IqXNQT+cLr3ACY80B2ZZprdNnpZrGC+D6w 3ZY59ddHAzjK1NChUNjQ4YRDsHHAegF1t77Lp3qWaWOJYMIMYH5Wr8o9/oth2m67ISWhGMkAk zH/zw7lqjNSnKWB+xFbay5aCiU+SzdIZ2RnEdBRpLeAk1YmglDbwmfHdos4WBg0LX+hXXlIMu 1y5MbY8kJlRDh6+++q19hD+Rj40vhqH4mmEXnqB8jlAw/2qmkTBkF5QesBuh0lUwThFkLCro/ /kcmrWxRpVZTlU43JzYmzCp5BEQNHgrzvfhkZJzvrjMktnFeaCbBjaMDGRt0x+JKbhWgiS760 uQEsXbBLqFKfwSCIkdd0rAIRO5ucLo/TVLF8ZfKwj1R9uX+fb0u+qKoHBsgFyLkwoXzh7P/xM G3wbDbi2O4kM2cq2Tj5ONo2dsYxYOGvJUN2BjR4lYA6fU5CDRgavh5bgrGvcNaWE4tY42uURW rOOuAYdeuoO7WpSfZHdsihys2mjZ5+eFPQnq+Kb9GEkQC1dZiTkI6LHUK4rbSc46K3Yc= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:125061 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --tD3t34prxlTrAjm0SogJ40STNHH19UsVx Content-Type: multipart/mixed; boundary="t115ug2oH65oQ7tPtvjJVQX5bkBl2Qxhi"; protected-headers="v1" From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= To: Lukas Juhrich , Noam Postavsky Cc: 24401@debbugs.gnu.org Message-ID: <220cf6b0-de5c-7d4b-410e-97c0a37d768c@live.com> Subject: Re: bug#24401: python-shell-completion-native-try returns incorrect results with python 3.5.2 References: <1d47cad6-227f-280a-2645-d97b45bbda44@live.com> <184c70a4-edba-b253-8d7b-2c15d67dacfc@live.com> <3d4d75b1-3de1-4edb-abf3-2dd5b1f75e75@wh2.tu-dresden.de> In-Reply-To: <3d4d75b1-3de1-4edb-abf3-2dd5b1f75e75@wh2.tu-dresden.de> --t115ug2oH65oQ7tPtvjJVQX5bkBl2Qxhi Content-Type: multipart/mixed; boundary="------------C6A1A2FCC05117AD4D561322" This is a multi-part message in MIME format. --------------C6A1A2FCC05117AD4D561322 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Lukas, Thanks for the patch! I prepared a similar one, but I didn't end up pushing it, because the bug= has a more complex root cause. Essentially, the issue is that completio= n doesn't work for empty strings in when python-shell-interpreter points = to Python 3 (see also the original bug report, #22897). A good way to experiment with this is to copy the completion code to a se= parate file (I attached it) and run python -i completion.py. In python 2= =2E7, pressing TAB shows a bunch of completions. In 3.5, it just inserts= a tab. Can you help figure out why this happen? Then we could fix the root of t= his bug. Cheers, Cl=C3=A9ment. On 2016-10-26 21:34, Lukas Juhrich wrote: > Hi, >=20 > On 10.09.2016 06:00, Cl=C3=A9ment Pit--Claudel wrote: >> Does anyone object to the proposed fix? >> >> Cl=C3=A9ment. >> >=20 > May I as a complete outsider to emacs development ask what the state > on this is? To me it looks like this just hasn't been done yet. >=20 > If having a patch file makes things easier, there is one attached; Let > me know if I can help otherwise. >=20 >=20 > -- > Sincerely, > Lukas Juhrich >=20 --------------C6A1A2FCC05117AD4D561322 Content-Type: text/x-python-script; name="completion.py" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="completion.py" def __PYTHON_EL_native_completion_setup(): try: import readline try: import __builtin__ except ImportError: # Python 3 import builtins as __builtin__ builtins =3D dir(__builtin__) is_ipython =3D ('__IPYTHON__' in builtins or '__IPYTHON__active' in builtins) class __PYTHON_EL_Completer: '''Completer wrapper that prints candidates to stdout. It wraps an existing completer function and changes its behav= ior so that the user input is unchanged and real candidates are prin= ted to stdout. Returned candidates are '0__dummy_completion__' and '1__dummy_completion__' in that order ('0__dummy_completion__= ' is returned repeatedly until all possible candidates are consume= d). The real candidates are printed to stdout so that they can be= easily retrieved through comint output redirect trickery. ''' PYTHON_EL_WRAPPED =3D True def __init__(self, completer): self.completer =3D completer self.last_completion =3D None self.print_mode =3D True def __call__(self, text, state): if state =3D=3D 0: # Set the first dummy completion. self.last_completion =3D None completion =3D '0__dummy_completion__' else: completion =3D self.completer(text, state - 1) if not completion: if self.last_completion !=3D '1__dummy_completion__':= # When no more completions are available, returni= ng a # dummy with non-sharing prefix allow ensuring ou= tput # while preventing changes to current input. # Coincidentally it's also the end of output. completion =3D '1__dummy_completion__' elif completion.endswith('('): # Remove parens on callables as it breaks completion = on # arguments (e.g. str(Ari)). completion =3D completion[:-1] self.last_completion =3D completion if completion in ( '0__dummy_completion__', '1__dummy_completion__')= : return completion elif completion: # For every non-dummy completion, return a repeated d= ummy # one and print the real candidate so it can be retri= eved # by comint output filters. if self.print_mode: print (completion) return '0__dummy_completion__' else: return completion else: return completion completer =3D readline.get_completer() if not completer: # Used as last resort to avoid breaking customizations. import rlcompleter completer =3D readline.get_completer() if completer and not getattr(completer, 'PYTHON_EL_WRAPPED', Fals= e): # Wrap the existing completer function only once. new_completer =3D __PYTHON_EL_Completer(completer) if not is_ipython: readline.set_completer(new_completer) else: # Try both initializations to cope with all IPython versi= ons. # This works fine for IPython 3.x but not for earlier: readline.set_completer(new_completer) # IPython<3 hacks readline such that `readline.set_comple= ter` # won't work. This workaround injects the new completer # function into the existing instance directly: instance =3D getattr(completer, 'im_self', completer.__se= lf__) instance.rlcomplete =3D new_completer if readline.__doc__ and 'libedit' in readline.__doc__: print("AAA") readline.parse_and_bind('bind ^I rl_complete') else: print("BBB") readline.parse_and_bind('tab: complete') # Require just one tab to send output. readline.parse_and_bind('set show-all-if-ambiguous on') print ('python.el: native completion setup loaded') except: print ('python.el: native completion setup failed') __PYTHON_EL_native_completion_setup() --------------C6A1A2FCC05117AD4D561322-- --t115ug2oH65oQ7tPtvjJVQX5bkBl2Qxhi-- --tD3t34prxlTrAjm0SogJ40STNHH19UsVx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYEXYdAAoJEPqg+cTm90wjX9sQALPSahbyxj5JfDpvn07Xeovw 0/nW4C2DdVaaoQcIVZcRVoTtdGm9dDNo87DNdgfk9V9JriKX1V/YsF4HVnmtoD/q ckGyx77nvPfS2Or71d+gZEYvVniwFNj5zyKfWrz/H0rit/+WG4/bcxbMeM1M0pCB smG+TmCJg563UF4TboBJfgHgt2YPaRLY8YrbxGWV0Q5Uu+QOMtnVnmJplb8wdfwI VQKhEFPwpbjK6zD1IzIKD/u50MPrIHAnqgFd3uAgm+e5Ho06nsnOJgSLSwFI5mq8 1uUYx0FzQzQ9PzEUi0J93OASNXIbt1G24YP+vgR6qgVxVl8WXb8US0AyfS2MTWcD ZGk5GwvLScw7mLWdsU5usR5BtcDK0vagjBlCriCWdyWcZtV5kWr7TEAtosf56YWL XPLZna2EqcOnGbPSC0SUHR2wjnqsgm8G5zxOIEXPFAo2TohdBt9gKK/UmIrIqLCm 1wXlra0i9SnnfdSJOnUMCL8+pPQYk0lH5obLOtpWE7NTwL/v907DlPmrX76zrplp TD2lSx5u4A0b72NsMfA/i7VV1OaCoB0KpJhjUwCF/UbwT0E49f9S0O2MiNU/WrdF 74HxafZzV397w2QdVraBo/Hwnt2bFMrpTRAP2RzhquPi+f62ipbCNyrEkVQv7h+y 6JxfztpUjDxQUoyTVlx1 =xEiM -----END PGP SIGNATURE----- --tD3t34prxlTrAjm0SogJ40STNHH19UsVx--