This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jbasko
Recipients jbasko
Date 2019-01-24.07:57:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548316625.2.0.852101004839.issue35815@roundup.psfhosted.org>
In-reply-to
Content
I am creating and registering singleton instances of subclasses of ABC in the ABC's __init_subclass__ and I just noticed that I am able to instantiate even the classes which have abstract methods.



import abc


class Base(abc.ABC):
    def __init_subclass__(cls, **kwargs):
        instance = cls()
        print(f"Created instance of {cls} easily: {instance}")


    @abc.abstractmethod
    def do_something(self):
        pass


class Derived(Base):
    pass


Actual Output:

Created instance of <class '__main__.Derived'> easily: <__main__.Derived object at 0x10a6dd6a0>

Expected Output:

TypeError: Can't instantiate abstract class Derived with abstract methods do_something
History
Date User Action Args
2019-01-24 07:57:07jbaskosetrecipients: + jbasko
2019-01-24 07:57:05jbaskosetmessageid: <1548316625.2.0.852101004839.issue35815@roundup.psfhosted.org>
2019-01-24 07:57:05jbaskolinkissue35815 messages
2019-01-24 07:57:05jbaskocreate