[New-bugs-announce] [issue18737] Get virtual subclasses of an ABC

Christian Heimes report at bugs.python.org
Wed Aug 14 15:13:13 CEST 2013

New submission from Christian Heimes:

ABCs are missing one important introspection feature. They have no API to get registered virtual subclasses. The patch implements a new method get_virtual_subclasses(recurse=False).

ABC.get_virtual_subclasses() returns the direct virtual subclasses of an ABC. ABC.get_virtual_subclasses(recuse=True) also takes subclasses of the ABC as well as subclasses of registered virtual classes into account.

>>> import numbers
>>> numbers.Number.get_virtual_subclasses()
>>> numbers.Number.get_virtual_subclasses(True)
{<class 'float'>, <class 'bool'>, <class 'int'>, <class 'complex'>}
>>> numbers.Integral.get_virtual_subclasses()
{<class 'int'>}
>>> numbers.Integral.get_virtual_subclasses(True)
{<class 'int'>, <class 'bool'>}

components: Library (Lib)
files: virtual_subclasses.patch
keywords: patch
messages: 195150
nosy: christian.heimes, rhettinger, stutzbach
priority: normal
severity: normal
stage: patch review
status: open
title: Get virtual subclasses of an ABC
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file31290/virtual_subclasses.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list