title: Define python built-in range specialized for a built-in (or not) type
body: <p>Let's say I implement a class named <code>MyClass</code>. I know that it's possible to implement built-in functions specialized behavior for the class that I define. For instance I can implement <code>MyClass.__repr__</code> which will be called if I use it on an instance of <code>MyClass</code>. Because <code>range</code> is also a built-in function, is it possible to implement the specialized behavior of <code>range</code> for <code>MyClass</code>?</p>
  
  <p>Let's suppose that I have a class on which I know that I can iterate (as like as i know I can iterate over integers). For instance Fraction:</p>
  
  <pre><code>&gt;&gt;&gt; from fractions import Fraction as F
  &gt;&gt;&gt; range(F(0,3),F(3,3),F(1,3))
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: range() integer end argument expected, got Fraction.
  </code></pre>
  
  <p>Obviously I could implement them with a different name. I'm just curious how far the duck typing approach could go.</p>
  
  <p>Edit: The expected behavior for <code>range(F(0,3),F(3,3),F(1,3))</code> is to return <code>[F(0,3), F(1,3), F(2,3)]</code>.</p>
  
  <p>Edit: So that we do not focalize on Fractions, I give another example. I use a library for physical dimensions (pint). Let's say I want to iterate from 0 seconds to 10 seconds, by 1 second.</p>
  
  <pre><code>&gt;&gt;&gt; from pint import UnitRegistry
  &gt;&gt;&gt; from numpy import arange
  &gt;&gt;&gt; ur = UnitRegistry()
  &gt;&gt;&gt; arange(0*ur.s, 10*ur.s, 1*ur.s)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ValueError: setting an array element with a sequence.
  &gt;&gt;&gt; range(0*ur.s, 10*ur.s, 1*ur.s)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "build/bdist.linux-x86_64/egg/pint/quantity.py", line 365, in __int__
  pint.errors.DimensionalityError: Cannot convert from 'second' to 'dimensionless'
  </code></pre>