Issue1265
Created on 2007-10-11 16:00 by christian.heimes, last changed 2008-01-06 22:29 by admin.
|
msg56346 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-10-11 16:00 |
|
found a pretty annoying bug caused by with blocks. A with block
terminates the debugging session and the program keeps running. It's not
possible to go to the next line with 'n'. 's' steps into the open() call.
# pdbtest.py
import pdb
pdb.set_trace()
print("before with")
with open("/etc/passwd") as fd:
data = fd.read()
print("after with")
print("end of program")
$ ./python pdbtest.py
> /home/heimes/dev/python/py3k/pdbtest.py(3)<module>()
-> print("before with")
(Pdb) n
before with
> /home/heimes/dev/python/py3k/pdbtest.py(4)<module>()
-> with open("/etc/passwd") as fd:
(Pdb) n
after with
end of program
|
|
msg57049 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-11-02 13:27 |
|
The bug makes debugging a crux :(
|
|
msg57433 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) |
Date: 2007-11-13 01:06 |
|
Corrected by revision 58958.
"with" is innocent. The problem is this function in abc.py which uses a
generator expression:
def __instancecheck__(cls, instance):
"""Override for isinstance(instance, cls)."""
return any(cls.__subclasscheck__(c)
for c in {instance.__class__, type(instance)})
It is called both by pdb (deep inside 'print') and the debugged code (in
PyObject_MethodCall), and this reveals the bug.
|
|
msg57435 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) |
Date: 2007-11-13 01:19 |
|
__instancecheck__ should be simpler: all classes are new-style, how is
it possible to have different results for
instance.__class__
and
type(instance)
?
|
|
msg57436 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-11-13 01:43 |
|
Good work Amaury! :)
I also wonder how type(cls) != cls.__class__ is possible with new style
classes. So far I found only one way and it ain't beautiful:
>>> class Meta(type):
... def __getattribute__(self, key):
... if key == "__class__": return object
... return type.__getattribute__(self, key)
...
>>> class Example(metaclass=Meta): pass
...
>>> Example.__class__
<type 'object'>
>>> type(Example)
<class '__main__.Meta'>
|
|
msg57438 - (view) |
Author: Guido van Rossum (gvanrossum) |
Date: 2007-11-13 05:14 |
|
Good work indeed!
Here's another way:
>>> class C:
... @property
... def __class__(self): return D
...
>>> class D: pass
...
>>> C().__class__
<class '__main__.D'>
>>>
|
|
msg57439 - (view) |
Author: Guido van Rossum (gvanrossum) |
Date: 2007-11-13 05:19 |
|
BTW: if you can show (e.g. with your unittest) that this indeed breaks
in 2.6 and 2.5, please do backport it.
BTW**2: I've noticed that abc.py's __instancecheck__ gets called a lot
at times when I don't expect it. Can you research this a bit?
|
|
msg57440 - (view) |
Author: Guido van Rossum (gvanrossum) |
Date: 2007-11-13 05:20 |
|
PPSS. When backporting, a note in Misc/NEWS is appreciated.
|
|
msg57443 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) |
Date: 2007-11-13 09:27 |
|
> BTW**2: I've noticed that abc.py's __instancecheck__ gets called a lot
> at times when I don't expect it. Can you research this a bit?
In classobject.c, method_call() calls PyObject_IsInstance() on the first
arg when the method is unbound.
This happens a lot in io.py, each time the code calls a base class method.
|
|
| Date |
User |
Action |
Args |
| 2008-01-06 22:29:45 | admin | set | keywords:
- py3k versions:
Python 3.0 |
| 2007-11-17 22:27:59 | gvanrossum | link | issue1454 superseder |
| 2007-11-13 09:27:34 | amaury.forgeotdarc | set | messages:
+ msg57443 |
| 2007-11-13 05:20:20 | gvanrossum | set | messages:
+ msg57440 |
| 2007-11-13 05:19:34 | gvanrossum | set | messages:
+ msg57439 |
| 2007-11-13 05:14:01 | gvanrossum | set | messages:
+ msg57438 |
| 2007-11-13 01:43:57 | christian.heimes | set | status: open -> closed resolution: accepted -> fixed messages:
+ msg57436 keywords:
+ py3k |
| 2007-11-13 01:19:07 | amaury.forgeotdarc | set | messages:
+ msg57435 |
| 2007-11-13 01:06:09 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages:
+ msg57433 |
| 2007-11-02 13:27:43 | christian.heimes | set | priority: high type: behavior resolution: accepted messages:
+ msg57049 |
| 2007-10-11 17:40:46 | gvanrossum | set | nosy:
+ gvanrossum |
| 2007-10-11 16:00:52 | christian.heimes | create | |
|