Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:21:42+00:00 2026-06-07T15:21:42+00:00

The intention was to implement some sort of plugin framework, where plugins are subclasses

  • 0

The intention was to implement some sort of plugin framework, where plugins are subclasses (i.e. B) of the same base class (i.e. A). The base class is loaded with standard import, whereas subclasses are loaded with imp.load_module() from the path of a well-known package (i.e. pkg).

pkg/
    __init__.py
    mod1.py
        class A
    mod2.py
        class B(pkg.mod1.A)

This worked fine with real subclasses, i.e.,

# test_1.py
import pkg
from pkg import mod1
import imp
tup = imp.find_module('mod2', pkg.__path__)
mod2 = imp.load_module('mod2', tup[0], tup[1], tup[2])
print(issubclass(mod2.B, mod1.A)) # True

But the problem came when testing the base class itself,

# test_2.py
import pkg
from pkg import mod1
import imp
tup = imp.find_module('mod1', pkg.__path__)
mod0 = imp.load_module('mod1', tup[0], tup[1], tup[2])
print(issubclass(mod0.A, mod1.A)) # False

But mod0.A and mod1.A are actually the same class from the same file (pkg/mod1.py).

This issue appears in both python 2.7 and 3.2.

Now the question is two-fold, a) Is it an expected feature or a bug of issubclass(), and b) How to get rid of this without changing contents of pkg?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:21:44+00:00Added an answer on June 7, 2026 at 3:21 pm

    They aren’t the same class. They were created with the same code, but since you executed that code twice (once in the import and once in load_module) you get two different class objects. issubclass is comparing the identities of the class objects and they’re different.

    Edit: since you can’t rely on issubclass, one possible alternative is to create a unique attribute on the base class that will be inherited by the derived classes. This attribute will exist on copies of the class as well. You can then test for the attribute.

    class A:
        isA = True
    
    class B(A):
        pass
    
    class C:
        pass
    
    def isA(aclass):
        try:
            return aclass.isA
        except AttributeError:
            return False
    
    print isA(A)
    True
    print isA(B)
    True
    print isA(C)
    False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement some sort of lookup table in C++ that will act
Suppose I have some Message class like the following. (This is a made-up class
I would like to implement some geometrical algorithms with numerical robustness. For this, a
Going through some excercises to hone my binary tree skills, I decided to implement
Currently I'm trying to implement some kind of object stream, similar to the structure
Thanks for reading. I'm using Unity framework to implement dependency injection in my app
Consider some sort of Personal Information Management presentation with a PimDetailVm that takes a
Possible Duplicate: Sort a Custom Class List<> I have a Generic Collector List and
I am trying to serialize some objects of class InstitutionResultView which is basically wrapper
I'm currently trying to implement some functionality as below with template metaprogramming typedef void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.