This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Spurious errors taking bool of dead proxy
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: colander_man, nnorwitz, rhettinger, tim.peters
Priority: high Keywords:

Created on 2004-06-23 15:48 by colander_man, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
weakref.patch nnorwitz, 2004-06-25 02:57 fix 1 w/test
Messages (7)
msg21256 - (view) Author: Chris King (colander_man) Date: 2004-06-23 15:48
The following code will cause interesting errors:

from weakref import proxy
class a: pass
bool(proxy(a()))

Entered at a prompt, this will not cause a
ReferenceError until another statement is entered (and
will instead return True or 1) in both 2.3 and 2.2.

Run as a script, this will return True and cause a
fatal error in 2.3, but will return 1 and otherwise
exhibit no strange behaviour in 2.2 (even with
additional code accessing the return value).

The equivalent code written using ref rather than proxy
works as expected: bool(ref(a())()) returns False and
creates no errors.
msg21257 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-06-23 20:13
Logged In: YES 
user_id=80475

Confirmed the script behavior in Py2.4.

The interactive prompt results are not consistent It
returned True the first time I ran it and raised a
ReferenceError in subsequent attempts.
msg21258 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-06-25 02:46
Logged In: YES 
user_id=33168

I believe the fix is in Objects/weakrefobject.c, line 358.
-1 should be returned, not 1 since an error occurred in
proxy_checkref().  I'll try to fix this.  If anyone wants to
steal it, feel free. :-)

Chris, if you could test the fix and report your results,
that would be great.
msg21259 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-06-25 02:57
Logged In: YES 
user_id=33168

attaching patch w/test
msg21260 - (view) Author: Chris King (colander_man) Date: 2004-06-25 13:47
Logged In: YES 
user_id=573252

The fix works (plus gave me an excuse to download the 2.4
snapshot). Thanks!
msg21261 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-06-26 02:46
Logged In: YES 
user_id=31435

Neal, FWIW, your fix is certainly correct.
msg21262 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-07-08 01:22
Logged In: YES 
user_id=33168

Checked in as: 
 * Objects/weakrefobject.c 1.18
 * Lib/test/test_weakref.py 1.42
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40438
2004-06-23 15:48:54colander_mancreate