On Wed, Jun 17, 2020 at 6:33 PM Stephan Hoyer <shoyer@gmail.com> wrote:
On Wed, Jun 17, 2020 at 5:31 PM Guido van Rossum <guido@python.org> wrote:
Could you please post a corrected version of the script?
Also, IMO the right way to test at runtime is still the numeric tower. The SupportsXxx classes are a crutch for static type checkers and their operational definition is "does the object have a __xxx__ method". The best way to discover at runtime whether something's an integer is still the numeric tower. (With one big caveat: I don't know whether numpy supports this. Last I looked there was scant mention of the numeric tower in the numpy docs, but IIRC there is code in numpy that uses it.)
NumPy's scalar types (e.g., float32 and int64) support the numeric tower.
Thanks for confirming my old memory.
NumPy's array types don't, because they aren't substitutable for single numbers. But you can check dtypes with NumPy's own type hierarchy: https://numpy.org/devdocs/reference/arrays.scalars.html
Sure, because they aren't numbers! IIRC there's an edge case where numpy treats an array containing a single number as a number? Well that's probably fine. A bigger issue (for some) is that Decimal does not respect the numeric tower. But then, Decimal doesn't respect anything besides the IEEE standard. :-/ -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>