473,555 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

when does issubclass fail?

Heyas folks,

When does issubclass fail? That's a loaded question so here's my test
case (also available at http://cmg.dok.org/code/classimports.tar.gz):

directory structure:

../test.py
../d/__init__.py
../d/b.py
../c/__init__.py
../c/a.py

#--------[a.py]---------
class A(object):
pass
#------[end a.py]-------

#--------[b.py]---------
import sys
sys.path.append ("/home/cmg/src/python/classtest/a")
class B(a.A):
pass
#------[end b.py]-------

#--------[test.py]------
import c.a
import d.b
print issubclass(d.b. B,c.a.A)
#--------[end test.py]--

issubclass(d.b. B,c.a.A) => False

I'm trying to figure out why this is failing. My guess is that there
are two distinct imports of a.A in memory though I can't come up with
a simple test case that makes this happen without manipulating
sys.path.

My goal is to define a baseclass BasePoller and then have user
configured directories searched for that baseclass so I can load
modules at run time. Since I can't do absolute imports, I treat that
directory as a suitable spot to import from and do some fancy dir()
walking to find instances of my subclass.

This work fine as long as the path I search is contained within an
original element of the main init script. I'm trying to handle the
case where the directory is specified as an absolute path and can't
come up with a way to make issubclass work.

Is there anyway out of this other than defining a special attribute I
can check for the presense of?
--
Chris Green <cm*@dok.org>
A watched process never cores.
Jul 18 '05 #1
1 2174
Chris Green wrote:
Heyas folks,

When does issubclass fail? That's a loaded question so here's my test
case (also available at http://cmg.dok.org/code/classimports.tar.gz):

directory structure:

./test.py
./d/__init__.py
./d/b.py
./c/__init__.py
./c/a.py

#--------[a.py]---------
class A(object):
pass
#------[end a.py]-------

#--------[b.py]---------
import sys
sys.path.append ("/home/cmg/src/python/classtest/a")
class B(a.A):
pass
#------[end b.py]-------

#--------[test.py]------
import c.a
import d.b
print issubclass(d.b. B,c.a.A)
#--------[end test.py]--

issubclass(d.b. B,c.a.A) => False

I'm trying to figure out why this is failing. My guess is that there
are two distinct imports of a.A in memory though I can't come up with
a simple test case that makes this happen without manipulating
sys.path.
The simplest demo for this problem is importing the __main__ script
a second time as a module:
-----[foo.py]-----
class A:
pass

import foo

print issubclass(A, foo.A)
------------------

executing "python foo.py" prints
True
False
[...]


Bye,
Walter Dörwald

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1534
by: John J. Lee | last post by:
Bare "except:", with no exception specified, is nasty because it can easily hide bugs. There is a case where it seemed useful to me in the past. Now it seems like a bad idea to me (but I think I might still be confused about it, hence this post). It's this: When you're processing a input from a file-like object connected to an external...
4
3423
by: Nathan Bullock | last post by:
Okay I have two files: a.py: ----- class cla_a(object): pass class cla_c(object): pass if __name__ == "__main__": mod = __import__("b")
11
4278
by: Rob Conner | last post by:
I'm still working on my DateTime class from last week... Why does __init__ not get called? The docs at http://www.python.org/dev/doc/devel/ref/customization.html read "If __new__() returns an instance of cls, then the new instance's __init__() method will be invoked" and as far as I can tell cls is very much an instance of DateTime ...
5
1780
by: deko | last post by:
I've heard it said that you only want to use a number (e.g. integer, long, etc.) if you are going to do calculations or some kind of math with it. Is this true? For example, I run a validate routine that checks an address entry - if something's missing in the entry, the code does different things based on what is missing, indicated my a 2 or...
20
7487
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable, but this seems to rely on a call from the application, e.g. MyClass.Dispose()
16
4961
by: lawrence k | last post by:
I've a file upload script on my site. I just now used it to upload a small text document (10k). Everything worked fine. Then I tried to upload a 5.3 meg Quicktime video. Didn't work. I've set the POST limit in php.ini to 8 megs. What reasons, other than the POST limit, would a large upload fail?
6
1579
by: Diwa | last post by:
Does istringstream require one whitespace at a min ? In the code below I expected "first" and "secondline" to be printed. Only "first" got printed. The code is as follows: // ----------------------------------------------------------------- #include <iostream // std::cout #include <fstream // ifstream #include <sstream ...
31
12715
by: banansol | last post by:
Hi, I just want to get this right. A call to realloc() will return NULL on error and the original memory is left untouched, both when requesting a larger or a smaller size that the original, right? But a call to realloc() with size set to zero is equivalent to free(), with returns void. Does that mean that a call to realloc() can fail when...
2
2551
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). -- Paul for cls in (A,B,C,D): seen = set()
0
8060
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5452
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3596
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.