New submission from Sylvain Marie <sylvain.ma...@schneider-electric.com>:
This issue is created following the discussion [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module. The following items are suggested: - adding a 'Boolean' ABC class to the 'numbers' module - register python 'bool' as a virtual subclass of both 'Boolean' and 'Integral' - register numpy bool ('np.bool_') as a virtual subclass of 'Boolean' only - rename 'Integral' 'Integer' and leave 'Integral' as an alias for backwards compatibility Below is a proposal Boolean class: --------------------- class Boolean(metaclass=ABCMeta): """ An abstract base class for booleans. """ __slots__ = () @abstractmethod def __bool__(self): """Return a builtin bool instance. Called for bool(self).""" @abstractmethod def __and__(self, other): """self & other""" @abstractmethod def __rand__(self, other): """other & self""" @abstractmethod def __xor__(self, other): """self ^ other""" @abstractmethod def __rxor__(self, other): """other ^ self""" @abstractmethod def __or__(self, other): """self | other""" @abstractmethod def __ror__(self, other): """other | self""" @abstractmethod def __invert__(self): """~self""" # register bool and numpy bool_ as virtual subclasses # so that issubclass(bool, Boolean) = issubclass(np.bool_, Boolean) = True Boolean.register(bool) try: import numpy as np Boolean.register(np.bool_) except ImportError: # silently escape pass # bool is also a virtual subclass of Integral. np.bool_ is not. Integral.register(bool) ---------- components: Library (Lib) messages: 312416 nosy: smarie priority: normal severity: normal status: open title: new Boolean ABC in numbers module + Integral>Integer renaming type: enhancement versions: Python 3.7, Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32886> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com