Thank you! For some reason I didn't think of using issubclass and isinstance in my Python types investigation. As you may have already noticed, I am a Python beginner. I also happen to have a Logic and Foundations of Mathematics background, hence I am tempted to investigate Python's type taxonomy from a basic mathematical angle, with an eye to "recovering" basic mathematical notions such as set membership, set inclusion etc. So far, I have been living under the impression that type() is akin to set membership (in a meta-Python approach), hence it should ideally match the results of isinstance(), but that does not happen:
>>> type(print) <class 'builtin_function_or_method'> >>> isinstance(print, builtin_function_or_method) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'builtin_function_or_method' is not defined Just curious why builtin_function_or_method doesn't work as an argument of isinstance(). After all, builtin_function_or_method is a type, right? The bottom line is that I am trying to figure out where exactly the world of Python types _diverges from_ what I would expect as a mathematician. It makes it easier for me to learn Python this way. Many thanks, C On Wed, Aug 28, 2019 at 11:56 PM Alan Bawden <a...@csail.mit.edu> wrote: > Cristian Cocos <cri...@ieee.org> writes: > > > Thank you! I can see that the taxonomy of built-in classes (i.e. the > > subclass/superclass relations) is not very developed. At the very least I > > would have loved to see stuff such as int declared as a subClass/subType > > of float and the like--that is, a class taxonomy in tune with standard > > mathematical practice, but I am guessing that mathematical kosher-ness > had > > to take a back seat to implementational concerns. > > Except that numbers of type `int' are _not_ a subset of numbers of > type `float'! Some ints are much larger that the largest float. > > In fact, both `int' and `float' are subclasses of `numbers.Real'. While it > is true that `numbers.Real' does not appear in the list returned by > `type.mro(int)', nevertheless `issubclass(int, numbers.Real)' and > `isinstance(2, numbers.Real)' are true. `type.mro' tells you something > about the _implementation_ of `int' and `float' that you _usually_ > shouldn't > concern yourself with. Stick to `isinstance' and `issubclass' and > everthing looks pretty kosher. > > -- > Alan Bawden > -- > https://mail.python.org/mailman/listinfo/python-list > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King -- https://mail.python.org/mailman/listinfo/python-list