Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2012-06-12 16:23:50 -0600

DSM gravatar image

Obviously the Python function should not accept a Sage type.

Why not? Python's abs calls __abs__, if it exists:

>>> class NotABuiltinClass(object):
...     def __abs__(self):
...         return 'fred'
... 
>>> a = NotABuiltinClass()
>>> abs(a)
'fred'

The wonders of duck typing. :^)

Obviously the Python function should not accept a Sage type.

Why not? Python's abs calls __abs__, if it exists:

>>> class NotABuiltinClass(object):
...     def __abs__(self):
...         return 'fred'
... 
>>> a = NotABuiltinClass()
>>> abs(a)
'fred'

The wonders of duck typing. :^):-)