[pypy-commit] pypy default: Document this as a (now-)known difference with CPython. Thanks

arigo noreply at buildbot.pypy.org
Fri May 29 16:04:32 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r77690:f501507f92d8
Date: 2015-05-29 16:04 +0200
http://bitbucket.org/pypy/pypy/changeset/f501507f92d8/

Log:	Document this as a (now-)known difference with CPython. Thanks
	kezabelle on irc.

diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -364,6 +364,18 @@
   wrappers.  On PyPy we can't tell the difference, so
   ``ismethod([].__add__) == ismethod(list.__add__) == True``.
 
+* in pure Python, if you write ``class A(object): def f(self): pass``
+  and have a subclass ``B`` which doesn't override ``f()``, then
+  ``B.f(x)`` still checks that ``x`` is an instance of ``B``.  In
+  CPython, types written in C use a different rule.  If ``A`` is
+  written in C, any instance of ``A`` will be accepted by ``B.f(x)``
+  (and actually, ``B.f is A.f`` in this case).  Some code that could
+  work on CPython but not on PyPy includes:
+  ``datetime.datetime.strftime(datetime.date.today(), ...)`` (here,
+  ``datetime.date`` is the superclass of ``datetime.datetime``).
+  Anyway, the proper fix is arguably to use a regular method call in
+  the first place: ``datetime.date.today().strftime(...)``
+
 * the ``__dict__`` attribute of new-style classes returns a normal dict, as
   opposed to a dict proxy like in CPython. Mutating the dict will change the
   type and vice versa. For builtin types, a dictionary will be returned that


More information about the pypy-commit mailing list