On Mon, Oct 16, 2017 at 3:58 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
Hi,

> What if we had a class, say time.time_base.  The user could specify the base
> units (such as "s", "ns", 1e-7, etc) and the data type ('float', 'int',
> 'decimal', etc.) when the class is initialized. (...)

It's easy to invent various funny new types for arbitrary precision.

But I prefer reusing the standard Python int type since it's very well
known and very easy to manipulate. There is not need to modify the
whole stdlib to support a new type. Moreover, we don't have to
"implement a new type".


I guess I wasn't clear.

I am not suggesting implementing a new numeric data type.  People wouldn't use the class directly like they would an int or float, they would simply use it to define the the precision and numeric type (float, int, decimal).  Then they would have access to the entire "time" API as methods.  So for example you could do something like:

   >>> import time
   >>>
   >>> ns_time_int = time.time_base(units='ns', type=int)
   >>> ms_time_dec = time.time_base(units=1e-6, type='Decimal')
   >>> s_time_float= time.time_base(units=1, type=float)  # This is identical to the existing "time" functions
   >>>
   >>> ns_time_int.clock()
   4978480000
   >>> ms_time_dec.clock()
   Decimal('5174165.999999999')
   >>> s_time_float.clock()
   5.276855
   >>>
   >>> ns_time_int.perf_counter()
   243163378188085
   >>> ms_time_dec.perf_counter()
   Decimal('243171477786.264')
   >>> s_time_float.perf_counter()
   243186.530955074