How well do you know Python?

Peter Otten __peter__ at web.de
Tue Jul 5 07:33:42 EDT 2016


Chris Angelico wrote:

> On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__ at web.de> wrote:
>> What will
>>
>> $ cat foo.py
>> import foo
>> class A: pass
>> print(isinstance(foo.A(), A))
>> $ python -c 'import foo'
>> ...
>> $ python foo.py
>> ...
>>
>> print?
> 
> I refuse to play around with isinstance and old-style classes.
> Particularly when circular imports are involved. Run this under Python
> 3 and/or explicitly subclass object, and then I'd consider it. :)

The intended lesson was that there may be two distinct classes

__main__.A and foo.A

Even though not just classes, but every object created in the script is 
affected this seems to cause the most subtle bugs.

Maybe the setup can be simplified or the question rephrased to make this 
clearer.





More information about the Python-list mailing list