[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Instantiating abstract classes
From: Peter Otten <__peter__ () web ! de>
Date: 2021-05-21 18:00:23
Message-ID: s88sfo$13je$1 () ciao ! gmane ! io
[Download RAW message or body]
Usually an abstract class cannot be instantiated:
>>> from abc import ABCMeta, abstractmethod
>>> from fractions import Fraction
>>> class A(Fraction, metaclass=ABCMeta):
@abstractmethod
def frobnicate(self): pass
>>> A()
Traceback (most recent call last):
File "<pyshell#287>", line 1, in <module>
A()
File "C:\Program Files\Python39-32\lib\fractions.py", line 93, in __new__
self = super(Fraction, cls).__new__(cls)
TypeError: Can't instantiate abstract class A with abstract method
frobnicate
However, if I derive from a builtin class that mechanism doesn't work:
>>> class A(int, metaclass=ABCMeta):
@abstractmethod
def frobnicate(self): pass
>>> A()
0
Is this a bug, or an implementation accident, or the expected behavior?
--
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic