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

  • SEARCH
  • Home
  • 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 9151519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:49:21+00:00 2026-06-17T11:49:21+00:00

What exactly does the last line of IClass do?? subclasscheck overloads subclasscheck but, normally

  • 0

What exactly does the last line of IClass do??

subclasscheck overloads subclasscheck but, normally while
overloading an operator we do something like:

adt + 4.0
here, adt is the user defined type = user class object(instance) and 4.0
is a builtin type which has say .real, .imaginary pre-configured so if
adt is complex then this becomes:
adt.(self, other)
add(self, other)
so a reference to ‘adt’ is generated and fed to ‘self’ and ‘other’ refers
to 4.0

But in the example below:

class IClass(object):
    def __init__(self):
        self.implementors = set()
    def register(self,C):
        self.implementors.add(C)
    def __instancecheck__(self,x):
        return self.__subclasscheck__(type(x))
    def __subclasscheck__(self,sub):
        return any(c in self.implementors for c in sub.mro())

# Now, use the above object
IFoo = IClass()
IFoo.register(Foo)
IFoo.register(FooProxy)

f = Foo()           # Create a Foo
g = FooProxy(f)     # Create a FooProxy
isinstance(f, IFoo)        # Returns True
isinstance(g, IFoo)        # Returns True
issubclass(FooProxy, IFoo) # Returns True

Here what are self and sub for subclasscheck?? How is
subclasscheck being overloaded??

Anyway, assuming it is being overloaded somehow.. a reference to FooProxy is
passed to self and IFoo->sub. So.. IFoo.mro() would generate the method
resolution order for instance IFoo and therefore for IClass.. which
would be just object.. umm.. wth??

Could somone explain what is going on here?? Basically ‘any’ should return
True if FooProxy is a sub-class of the grouped-classes in IClass.

  • 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-17T11:49:22+00:00Added an answer on June 17, 2026 at 11:49 am

    __subclasscheck__ is the method to override built-in issubclass.
    The call issubclass(X,Y) first checks whether Y.__subclasscheck__ exists, and if so, calls Y.__subclasscheck__(X) instead of its normal implementation.

    similarly;__instancecheck__ is the method to override built-in isinstance. The call isinstance(X, Y) first checks whether
    Y.__instancecheck__ exists, and if so, calls Y.__instancecheck__(X)
    instead of its normal implementation.

    In [121]: class FooProxy3(object):
         ...:     pass
    
    In [122]: issubclass(FooProxy3,IFoo)
    Out[122]: False
    
    In [123]: for c in IFoo.implementors:
         ...:     print c
         ...:     
    <class '__main__.Foo'>
    <class '__main__.FooProxy'>
    
    In [124]: for c in FooProxy3.mro():
         ...:     print c
         ...:     
    <class '__main__.FooProxy3'>
    <type 'object'>
    
    In [125]: IFoo.register(FooProxy3)
    
    In [126]: for c in IFoo.implementors:
         ...:     print c
         ...:     
    <class '__main__.Foo'>
    <class '__main__.FooProxy'>
    <class '__main__.FooProxy3'>
    
    In [127]: issubclass(FooProxy3,IFoo)
    Out[127]: True
    

    lets consider above example;create new class FooProxy3; and check issubclass for that; and it will return False (as per Out[122]) because we are looking for subclass check in IFoo.implementors; and there it is not present (as per In[123])
    but when we have register FooProxy(here it means; now we can see it IFoo.implementors); we can see it Foxproxy3 in IFoo.implementors (as per In[126])
    so when we check issubclass ; it wil return True.

    for more info;
    Customizing instance and subclass checks

    Overloading isinstance() and issubclass()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you please explain exactly what the last line of this does, and why
What exactly does execve() do? I've tried looking at the documentation (http://linux.die.net/man/2/execve) but given
What does the @posts line do exactly? def index if params[:user_id] && params[:artist_id] @id
How exactly does adding a random number to the end of an AJAX server
What exactly does SignedCookieJar do? And what is the difference from that and using
What exactly does putting extern C into C++ code do? For example: extern C
What exactly does a mobile need to be able to run JavaFX? Can it
What exactly does a finally block in exception handling perform?
What exactly does the Objective-C garbage collector collect? For example, if I'm writing a
I was wondering how exactly does TCP implement in-order delivery. lets say this is

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.