Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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. :^):-)