Why does super(bool) give None
Cecil Westerhof
Cecil at decebal.nl
Fri Apr 24 07:06:28 EDT 2020
Chris Angelico <rosuav at gmail.com> writes:
> On Fri, Apr 24, 2020 at 4:16 PM Cecil Westerhof <Cecil at decebal.nl> wrote:
>>
>> issubclass(bool, int) gives True
>> but
>> super(bool) gives <super: bool, None>
>>
>> Do I not understand the meaning of super, or is this inconsistent?
>>
>> (Until now I have not down much work with classes in Python.)
>>
>
> One-arg super is an unbound object, and the "None" just indicates
> that. (Although every Python that I've tried says NULL there, not
> None. What version are you using?)
That was because I was using ipython3, python does what you expect:
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> super(bool)
<super: <class 'bool'>, NULL>
When using ipython3 it goes like:
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: super(bool)
Out[1]: <super: bool, None>
> It doesn't say what "the parent class" is, because super doesn't
> actually work with parent classes - it lets you call the *next*
> class. (In complex inheritance trees, that can mean going across a
> diamond or anything.)
I have more learning to do as I tought. ;-)
> I've never actually looked at the repr of a super object - I've always
> just called a method on it immediately after constructing it. Never
> seen a need to hang onto one :)
Well, maybe I will never need it, but I am just curious. And sometimes
it was very handy that I had sought out 'useless' things.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
More information about the Python-list
mailing list