[issue14611] inspect.getargs fails on some anonymous tuples
New submission from Stefano Taschini : How to reproduce Take the following two functions: >>> def f(l, (x, y)): ...sup = max(u*x + v*y for u, v in l) ...return ((u, v) for u, v in l if u*x + v*y == sup) >>> def g((x, y)): ...def h(): ...return x + y ...return h Inspect.getargs will throw an exception on the former and return a wrong result on the latter:: >>> import inspect >>> inspect.getargs(f.__code__) Traceback (most recent call last): ... IndexError: list index out of range >>> inspect.getargs(g.__code__) Arguments(args=['h'], varargs=None, keywords=None) # h is most definitely not an argument of g! Analysis If you disassemble the two functions, you'll see that in both cases the anonymous tuples are unpacked using STORE_DEREF:: >>> import dis >>> dis.disassemble(f.__code__) 1 0 LOAD_FAST1 (.1) 3 UNPACK_SEQUENCE 2 6 STORE_DEREF 0 (x) 9 STORE_DEREF 2 (y) 2 12 LOAD_GLOBAL 0 (max) ... >>> dis.disassemble(g.__code__) 1 0 LOAD_FAST0 (.0) 3 UNPACK_SEQUENCE 2 6 STORE_DEREF 0 (x) 9 STORE_DEREF 1 (y) 2 12 LOAD_CLOSURE 1 (y) 15 LOAD_CLOSURE 0 (x) 18 BUILD_TUPLE 2 21 LOAD_CONST 1 () 24 MAKE_CLOSURE 0 27 STORE_FAST 3 (h) 4 30 LOAD_FAST3 (h) 33 RETURN_VALUE\ However, the implementation of inspect.getargs only looks for UNPACK_TUPLE, UNPACK_SEQUENCE, STORE_FAST. Notes - The version of Python used is:: >>> import sys >>> sys.version_info[:3] (2, 7, 3) -- components: Library (Lib) messages: 158599 nosy: taschini priority: normal severity: normal status: open title: inspect.getargs fails on some anonymous tuples type: behavior versions: Python 2.7 ___ Python tracker <http://bugs.python.org/issue14611> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12947] Examples in library/doctest.html lack the flags
Stefano Taschini added the comment: Concrete examples can be seen in the section http://docs.python.org/library/doctest.html#option-flags-and-directives For instance at http://docs.python.org/library/doctest.html#doctest.IGNORE_EXCEPTION_DETAIL The doctest flags present in the sources in http://docs.python.org/_sources/library/doctest.txt are all stripped. -- nosy: +taschini ___ Python tracker <http://bugs.python.org/issue12947> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14611] inspect.getargs fails on some anonymous tuples
Stefano Taschini added the comment: I'll give it a try. -- ___ Python tracker <http://bugs.python.org/issue14611> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue14611] inspect.getargs fails on some anonymous tuples
Stefano Taschini added the comment: I think this should do. inspect.getargs is now looking for STORE_DEREF besides STORE_FAST, and is making sure that the appropriate namespace (locals vs cell + free vars) is selected depending on the opcode. The only changes to the test suite are three additional tests, based on the two examples above. -- keywords: +patch Added file: http://bugs.python.org/file25269/issue_14611.patch ___ Python tracker <http://bugs.python.org/issue14611> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12947] Examples in library/doctest.html lack the flags
Stefano Taschini added the comment: As far as I can see, Sphinx has a global setting for trim_doctest_flags but lacks the possibility of locally disabling the trimming. A quick workaround would be to have the following sphinx extension added: class ProxyLexer(object): def __init__(self, underlying): self.__underlying = underlying def __getattr__(self, attr): return getattr(self.__underlying, attr) def setup(app): from sphinx.highlighting import lexers if lexers is not None: lexers['pycon-literal'] = ProxyLexer(lexers['pycon']) lexers['pycon3-literal'] = ProxyLexer(lexers['pycon3']) That would allow blocks marked as .. code-block:: pycon-literal or preceded by .. highlight:: pycon-literal to escape the trimming of doctest flags. If that's of any interest I can submit a patch. -- ___ Python tracker <http://bugs.python.org/issue12947> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1065986] Fix pydoc crashing on unicode strings
Changes by Stefano Taschini : -- nosy: +taschini ___ Python tracker <http://bugs.python.org/issue1065986> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1065986] Fix pydoc crashing on unicode strings
Stefano Taschini added the comment: Shouldn't this be reopened for Python 2.7 ? -- type: -> behavior versions: +Python 2.7 -Python 2.5 ___ Python tracker <http://bugs.python.org/issue1065986> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1065986] Fix pydoc crashing on unicode strings
Stefano Taschini added the comment: Oh well, in that case I guess we'll have to work around it. Here's the monkey patch I use to overcome this limitation in pydoc, in case others wish to add it to their PYTHONSTARTUP or sitecustomize: def pipepager(text, cmd): """Page through text by feeding it to another program.""" try: import locale except ImportError: encoding = "ascii" else: encoding = locale.getpreferredencoding() pipe = os.popen(cmd, 'w') try: pipe.write(text.encode(encoding, 'xmlcharrefreplace') if isinstance(text, unicode) else text) pipe.close() except IOError: pass # Ignore broken pipes caused by quitting the pager program. import pydoc pydoc.pipepager = pipepager del pydoc, pipepager -- ___ Python tracker <http://bugs.python.org/issue1065986> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Changes by Stefano Taschini : -- nosy: +taschini ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Stefano Taschini added the comment: Here's the patch. It has four goals: 1. Allow ./configure --disable-unicode to work; 2. Have the naked interpreter running with no unicode support; 3. Be able to compile most of the stdlib; 4. Be able to run the test suite. The one-line modification to configure.ac (and consequentley autoreconf'ed configure) achieve goal 1. The changes to the three C files (which are nothing more than a few #ifdef Py_USING_UNICODE) achieve goal 2: you can run "./python -S". The fix for site.py takes care of posixpath, glob, (and a few other modules) and makes it possible to compile most of the C extensions of the stdlib, goal 3 -- The compilation process under posix requires posixpath and glob to work. The most notable extension that won't be built is, unsurprisingly enough, io. Fortunately it does not play in Python 2.7 the central role it plays in Python 3. Still, a few other modules depend on it and won't be usable. The changes in Lib/test/script_helper.py and Lib/test/test_support.py make it possible to run the test suite. Roughly one third of the tests will fail, though, but I think that's acceptable. In relation to my purpose for submitting this patch ( #1065986 ) , I note that test_pydoc runs and succeeds. -- keywords: +patch Added file: http://bugs.python.org/file25377/issue8767.patch ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1065986] Fix pydoc crashing on unicode strings
Stefano Taschini added the comment: Here's my patch, along the lines of the work-around I posted earlier. A few remarks: 1. The modifications in pydoc only touch the four console pagers and the html pager (html.page). 2. A module-wide default encoding is initialized from locale.getpreferredencoding. Pagers that write to a file use the encoding of that file if defined, else they use the module-wide default. The html pager uses ascii. All of them use xml character entity replacement as fall-back. 3. An additional set of tests has been added to test.test_pydoc to verify the behaviour of the modifications. 4. No functionality is broken if Python is built without unicode support. -- Added file: http://bugs.python.org/file25380/issue1065986.patch ___ Python tracker <http://bugs.python.org/issue1065986> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Stefano Taschini added the comment: Martin, That was exactly my first approach. What made me change my mind is that i) it is also fairly hacky (one might rightfully object that it is the isinstance(x, unicode) tests that should be changed) ii) it is now a hack spread over a dozen files, instead of the site.py alone. iii) the alterations in those files are executed even in the case of built-in unicode support, thus increasing the risk of introducing a regression in the stdlib. In the end I was a bit loath to alter quite a few of the stdlib modules (including some of the "core" ones) for a rather infrequent case. My solution, on the other hand, is such that in the regular case of built-in unicode support those modules are not touched at all, thus reducing the risk of introducing a regression in the stdlib. Still, if you guys do think that the maintainability risk due to the hackiness of my suggestion exceeds the potential benefits, it might be better to split the issue (and the patch) into two: one for the autoconf and interpreter, and one for the stdlib. In this way, the patch for autconf and interpreter (which should be less controversial) might be accepted sooner, while we bide our time until we come up with a better solution for the stdlib. -- ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Changes by Stefano Taschini : Added file: http://bugs.python.org/file25418/issue8767_interpreter.patch ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Stefano Taschini added the comment: Here we go. -- Added file: http://bugs.python.org/file25419/issue8767_stdlib.patch ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12947] Examples in library/doctest.html lack the flags
Stefano Taschini added the comment: Ezio, the patch I attached goes into that direction, by adding a ":trim-doctest-flags: disable" option to the code blocks. I thought I had a good reason for having the option worded as ":trim-doctest-flags: disable" instead of ":keep-doctest-flags:", now I'm not so sure. Note: the patch is against the 2.7 branch. -- keywords: +patch Added file: http://bugs.python.org/file25424/issue12947_v0.patch ___ Python tracker <http://bugs.python.org/issue12947> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8767] Configure: Cannot disable unicode
Stefano Taschini added the comment: Understood and agreed. -- ___ Python tracker <http://bugs.python.org/issue8767> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4709] Mingw-w64 and python on windows x64
Changes by Stefano Taschini : -- nosy: +taschini ___ Python tracker <http://bugs.python.org/issue4709> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com