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 6817005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:59:42+00:00 2026-05-26T20:59:42+00:00

Take the following minimal example: import abc class FooClass(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def

  • 0

Take the following minimal example:

import abc

class FooClass(object):
  __metaclass__ = abc.ABCMeta

  @abc.abstractmethod
  def FooMethod(self):
    raise NotImplementedError()


def main():
  derived_type = type('Derived', (FooClass,), {})

  def BarOverride(self):
    print 'Hello, world!'
  derived_type.FooMethod = BarOverride

  instance = derived_type()

Running main() gets you:

TypeError: Can't instantiate abstract class Derived with abstract methods FooMethod

(The exception occurs on the instance = derived_type() line.)

But FooMethod shouldn’t be abstract: I’ve overridden it with BarOverride. So, why is this raising exceptions?

Disclaimer: Yes, I could use the explicit class syntax, and accomplish the exact same thing. (And even better, I can make it work!) But this is a minimal test case, and the larger example is dynamically creating classes. 🙂 And I’m curious as to why this doesn’t work.

Edit: And to prevent the other obvious non-answer: I don’t want to pass BarOverride in the third argument to type: In the real example, BarOverride needs to have derived_type bound to it. It is easier to do this if I can define BarOverride after the creation of derived_type. (If I can’t do this, then why?)

  • 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-05-26T20:59:43+00:00Added an answer on May 26, 2026 at 8:59 pm

    Because the docs say so:

    Dynamically adding abstract methods to a class, or attempting to
    modify the abstraction status of a method or class once it is created,
    are not supported. The abstractmethod() only affects subclasses
    derived using regular inheritance; “virtual subclasses” registered
    with the ABC’s register() method are not affected.

    A metaclass is only called when a class is defined. When abstractmethod has marked a class as abstract that status won’t change later.

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

Sidebar

Related Questions

Take the following generics example import java.util.List; import java.util.ArrayList; public class GenericsTest { private
Take the following class as an example: class Sometype { int someValue; public Sometype(int
take following class and two object definitions: class Rect{ public: enum centimeter; enum meter;
Take the following code example: File package1/__init__.py : from moduleB import foo print moduleB.__name__
Take the following example: class BookManager { ... }; class Book { public: void
Take the following code: class ChallengesController < ApplicationController def update @challenge = Challenge.find(params[:id]) @challenge.update!(params[:challenge])
Take the following example, class Cup {} class MyObject { protected $cups = array();
Take following example of code: (ASP.NET WebForms) <asp:Content ContentPlaceHolderID=Contents runat=server> <div class=blogpost-list> <asp:Repeater ID=blogList
Take the following class and unit test. public class Entity { public object Id
Take the following HTML for example: <div class=container> <div class=body>Content</div> <div class=body>Content</div> <div class=body>Content</div>

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.