aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-03-10 14:31:35 +0200
committerMatti Picus <matti.picus@gmail.com>2022-03-10 14:31:35 +0200
commitc317db6d8ce471ce2753e6e9e77b35495df19d19 (patch)
treeb639dcad05ac8eab9b03453cc8d30076d4d66165 /pypy/doc/cpython_differences.rst
parentadd release note to index (diff)
downloadpypy-c317db6d8ce471ce2753e6e9e77b35495df19d19.tar.gz
pypy-c317db6d8ce471ce2753e6e9e77b35495df19d19.tar.bz2
pypy-c317db6d8ce471ce2753e6e9e77b35495df19d19.zip
make code sample work on python3 (issue 3699)
Diffstat (limited to 'pypy/doc/cpython_differences.rst')
-rw-r--r--pypy/doc/cpython_differences.rst12
1 files changed, 8 insertions, 4 deletions
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
index 4a62a07d24..287f456abb 100644
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -162,6 +162,8 @@ Two examples::
class D(dict):
def __getitem__(self, key):
+ if key == 'print':
+ return print
return "%r from D" % (key,)
class A(object):
@@ -170,15 +172,17 @@ Two examples::
a = A()
a.__dict__ = D()
a.foo = "a's own foo"
- print a.foo
+ print(a.foo)
# CPython => a's own foo
# PyPy => 'foo' from D
+ print('==========')
+
glob = D(foo="base item")
loc = {}
- exec "print foo" in glob, loc
- # CPython => base item
- # PyPy => 'foo' from D
+ exec("print(foo)", glob, loc)
+ # CPython => base item, and never looks up "print" in D
+ # PyPy => 'foo' from D, and looks up "print" in D
Mutating classes of objects which are already used as dictionary keys