eryksun wrote: > On Tue, Aug 28, 2012 at 6:00 AM, Peter Otten <__pete...@web.de> wrote: >> >> Anyway here's an alternative implementation: >> >>>>> def vi(x): >> ... if not isinstance(x, numbers.Number): >> ... raise TypeError >> ... if not int(x) == x: >> ... raise ValueError > > You could test against numbers.Integral.
That would reject "floats with an integral value" and therefore doesn't comply with the -- non-existing -- spec. > But it's not fool-proof. Nothing is. The code attempts to make expectations more explicit than Steven did in his original implementation. > Someone can register an incompatible class with the abstract base > class (ABC). > > >>> import numbers > >>> isinstance("42", numbers.Integral) > False > >>> numbers.Integral.register(str) > >>> isinstance("42", numbers.Integral) > True That's quite an elaborate scheme to shoot yourself in the foot ;) _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor