[Python-Dev] isinstance() on old-style classes in Py 2.7
Hi. Today, I ran across this, in Python 2.7.6: >>> class C: ... pass ... >>> issubclass(C,object) False >>> isinstance(C(),object) True <-- ??? The description of isinstance() in Python 2.7 does not reveal this result (to my reading). >From a duck-typing perspective, one would also not guess that an instance of C would be considered an instance of object: >>> dir(C()) ['__doc__', '__module__'] >>> dir(object()) ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__ ', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] -> What is the motivation for isinstance(C,object) to return True in Python 2.7? Andy Andreas Maier IBM Senior Technical Staff Member, Systems Management Architecture & Design IBM Research & Development Laboratory Boeblingen, Germany [email protected], +49-7031-16-3654 IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] PyPy3 2.4.0 released
= PyPy3 2.4 - Snow White = We're pleased to announce PyPy3 2.4, which contains significant performance enhancements and bug fixes. You can download the PyPy3 2.4.0 release here: http://pypy.org/download.html PyPy3 Highlights Issues reported with our previous release were fixed after reports from users on our new issue tracker at https://bitbucket.org/pypy/pypy/issues or on IRC at #pypy. Here is a summary of the user-facing PyPy3 specific changes: * Better Windows compatibility, e.g. the nt module functions _getfinalpathname & _getfileinformation are now supported (the former is required for the popular pathlib library for example) * Various fsencode PEP 383 related fixes to the posix module (readlink, uname, ttyname and ctermid) and improved locale handling * Switched default binary name os POSIX distributions to 'pypy3' (which symlinks to to 'pypy3.2') * Fixed a couple different crashes related to parsing Python 3 source code Further Highlights (shared w/ PyPy2) Benchmarks improved after internal enhancements in string and bytearray handling, and a major rewrite of the GIL handling. This means that external calls are now a lot faster, especially the CFFI ones. It also means better performance in a lot of corner cases with handling strings or bytearrays. The main bugfix is handling of many socket objects in your program which in the long run used to "leak" memory. We fixed a memory leak in IO in the sandbox_ code We welcomed more than 12 new contributors, and conducted two Google Summer of Code projects, as well as other student projects not directly related to Summer of Code. * Reduced internal copying of bytearray operations * Tweak the internal structure of StringBuilder to speed up large string handling, which becomes advantageous on large programs at the cost of slightly slower small *benchmark* type programs. * Boost performance of thread-local variables in both unjitted and jitted code, this mostly affects errno handling on linux, which makes external calls faster. * Move to a mixed polling and mutex GIL model that make mutlithreaded jitted code run *much* faster * Optimize errno handling in linux (x86 and x86-64 only) * Remove ctypes pythonapi and ctypes.PyDLL, which never worked on PyPy * Classes in the ast module are now distinct from structures used by the compiler, which simplifies and speeds up translation of our source code to the PyPy binary interpreter * Win32 now links statically to zlib, expat, bzip, and openssl-1.0.1i. No more missing DLLs * Many issues were resolved_ since the 2.3.1 release in June .. _`whats-new`: http://doc.pypy.org/en/latest/whatsnew-2.4.0.html .. _resolved: https://bitbucket.org/pypy/pypy/issues?status=resolved .. _sandbox: http://doc.pypy.org/en/latest/sandbox.html We have further improvements on the way: rpython file handling, numpy linalg compatibility, as well as improved GC and many smaller improvements. Please try it out and let us know what you think. We especially welcome success stories, we know you are using PyPy, please tell us about it! Cheers The PyPy Team ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] isinstance() on old-style classes in Py 2.7
This is one of the unfortunate effects of the existence of "old-style" classes in Python 2. The old-style class hierarchy is distinct from the new-style class hierarchy, but instances of old-style classes are still objects (since in Python, *everything* is an object). For new code, and whenever you have an opportunity to refactor old code, you should use new-style classes, by inheriting your class from object (or from another class that inherits from object). On Tue, Oct 21, 2014 at 9:43 AM, Andreas Maier wrote: > > Hi. Today, I ran across this, in Python 2.7.6: > > >>> class C: > ... pass > ... > >>> issubclass(C,object) > False > >>> isinstance(C(),object) > True <-- ??? > > The description of isinstance() in Python 2.7 does not reveal this result > (to my reading). > > From a duck-typing perspective, one would also not guess that an instance > of C would be considered an instance of object: > > >>> dir(C()) > ['__doc__', '__module__'] > >>> dir(object()) > ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', > '__hash__', '__init__', '__new__', '__reduce__ > ', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', > '__subclasshook__'] > > -> What is the motivation for isinstance(C,object) to return True in Python > 2.7? > > Andy > > Andreas Maier > IBM Senior Technical Staff Member, Systems Management Architecture & Design > IBM Research & Development Laboratory Boeblingen, Germany > [email protected], +49-7031-16-3654 > > IBM Deutschland Research & Development GmbH > Vorsitzende des Aufsichtsrats: Martina Koederitz > Geschaeftsfuehrung: Dirk Wittkopp > Sitz der Gesellschaft: Boeblingen > Registergericht: Amtsgericht Stuttgart, HRB 243294 > > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] isinstance() on old-style classes in Py 2.7
Hi, The problem is a side effect of the fact that old-style classes are implemented on top of new-style meta-classes. Consequently although C is the "class" of C() it is not its "type". >>> type(C()) >>> type(C()).__mro__ (, ) therefore >>> issubclass(type(C()), object) True which implies >>> isinstance(C(),object) True Cheers, Mark. On 21/10/14 17:43, Andreas Maier wrote: Hi. Today, I ran across this, in Python 2.7.6: class C: ... pass ... issubclass(C,object) False isinstance(C(),object) True <-- ??? The description of isinstance() in Python 2.7 does not reveal this result (to my reading). From a duck-typing perspective, one would also not guess that an instance of C would be considered an instance of object: dir(C()) ['__doc__', '__module__'] dir(object()) ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__ ', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'] -> What is the motivation for isinstance(C,object) to return True in Python 2.7? Andy Andreas Maier IBM Senior Technical Staff Member, Systems Management Architecture & Design IBM Research & Development Laboratory Boeblingen, Germany [email protected], +49-7031-16-3654 IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschaeftsfuehrung: Dirk Wittkopp Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/mark%40hotpy.org ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] isinstance() on old-style classes in Py 2.7
On Oct 21, 2014, at 10:13 AM, Guido van Rossum wrote: >For new code, and whenever you have an opportunity to refactor old code, >you should use new-style classes, by inheriting your class from object (or >from another class that inherits from object). One nice way to do this module-globally is to set: __metaclass__ = type at the top of your file. Then when you're ready to drop Python 2, it's an easy clean up. Cheers, -Barry ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] isinstance() on old-style classes in Py 2.7
Hm. I've never been a fan of that. EIBTI and such... On Tue, Oct 21, 2014 at 10:53 AM, Barry Warsaw wrote: > On Oct 21, 2014, at 10:13 AM, Guido van Rossum wrote: > > >For new code, and whenever you have an opportunity to refactor old code, > >you should use new-style classes, by inheriting your class from object (or > >from another class that inherits from object). > > One nice way to do this module-globally is to set: > > __metaclass__ = type > > at the top of your file. Then when you're ready to drop Python 2, it's an > easy clean up. > > Cheers, > -Barry > ___ > Python-Dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (python.org/~guido) ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] isinstance() on old-style classes in Py 2.7
On Oct 21, 2014, at 11:22 AM, Guido van Rossum wrote: >Hm. I've never been a fan of that. EIBTI and such... Yeah, I just hate seeing `class Foo(object)` in Python 3 and am too lazy to clean up every class definition. ;) YMMV! Cheers, -Barry signature.asc Description: PGP signature ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] https://docs.python.org/3/using/index.html not linking correctly
On 2014-10-21 01:39, Terry Reedy wrote: On 10/20/2014 7:29 PM, MRAB wrote: On 2014-10-21 00:09, Eli Bendersky wrote: On Mon, Oct 20, 2014 at 1:01 PM, Terry Reedy mailto:[email protected]>> wrote: If I go to https://docs.python.org/3/using/index.html and click on any of the TOC entries, I get 'connecting' indefinitely. This problem seems unique to this file. I tried several other index files and clicking am entry brings up the corresponding page almost immediately. Works fine for me, Terry, in both Chrome and Firefox. Could be something in your browser/caching? Try "private mode" or whatever that's called in your browser of choice. Just tried the first link: https://docs.python.org/3/using/cmdline.html I also get 'Connecting' indefinitely. So I tested the link here: http://www.downforeveryoneorjustme.com/ It said: "It's not just you! http://https looks down from here." I am using Firefox, but the difference is that by happenstance, I was in privacy mode (perhaps for the first time with python.org -- I want the docs in the cache and history list -- because I accessed the docs to answer a StackOverflow question.) It is not just that document but also Execution model and Expression in Reference. (I tried each 3 times minutes apart.) I have not had a similiar problem with any Arstechnica or StackOverflow pages, or similar sites. So the solution for me is to use normal mode, but something seems not quite right in the interaction between privacy mode Firefox and python.org. No problem I could find with Internet Explorer's 'In Privacy' mode. I have/had occasional problems even though I was using normal mode. ___ Python-Dev mailing list [email protected] https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
