diff options
author | Matti Picus <matti.picus@gmail.com> | 2022-03-10 14:31:35 +0200 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2022-03-10 14:31:35 +0200 |
commit | c317db6d8ce471ce2753e6e9e77b35495df19d19 (patch) | |
tree | b639dcad05ac8eab9b03453cc8d30076d4d66165 /pypy/doc/cpython_differences.rst | |
parent | add release note to index (diff) | |
download | pypy-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.rst | 12 |
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 |