<div dir="ltr">I agree, we shouldn't pursue Todd's proposal. It's too complicated, for too little benefit.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 16, 2017 at 9:49 AM, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2017-10-16 18:13 GMT+02:00 Todd <<a href="mailto:toddrjen@gmail.com">toddrjen@gmail.com</a>>:<br>
> I am not suggesting implementing a new numeric data type. People wouldn't<br>
> use the class directly like they would an int or float, they would simply<br>
> use it to define the the precision and numeric type (float, int, decimal).<br>
> Then they would have access to the entire "time" API as methods. So for<br>
> example you could do something like:<br>
<br>
</span>I tried to include your idea in a more general description of "different API":<br>
<a href="https://www.python.org/dev/peps/pep-0564/#different-api" rel="noreferrer" target="_blank">https://www.python.org/dev/<wbr>peps/pep-0564/#different-api</a><br>
<span class=""><br>
> >>> import time<br>
> >>><br>
> >>> ns_time_int = time.time_base(units='ns', type=int)<br>
> >>> ms_time_dec = time.time_base(units=1e-6, type='Decimal')<br>
> >>> s_time_float= time.time_base(units=1, type=float) # This is<br>
> identical to the existing "time" functions<br>
> >>><br>
> >>> ns_time_int.clock()<br>
> 4978480000<br>
> >>> ms_time_dec.clock()<br>
> Decimal('5174165.999999999')<br>
> >>> s_time_float.clock()<br>
> 5.276855<br>
<br>
</span>*I* dislike this API. IMHO it's overcomplicated just to get the<br>
current time :-( For example, I wouldn't like to have to teach to a<br>
newbie "how to get the current time" with such API.<br>
<br>
I also expect that the implementation will be quite complicated.<br>
Somewhere, you will need an internal "standard" type to store time, a<br>
"master type" used to build all other types. Without that, you would<br>
have to duplicate code and it would be a mess. You have many options<br>
for such master time.<br>
<br>
For the private C API of CPython, I already "implemented" such "master<br>
type": I decided to use C int64_t type: it's a 64-bit signed integer.<br>
There is an API on top of it which is unit agnostic, while it uses<br>
nanoseconds in practice. The private "pytime" API supports many<br>
timestamps conversions to adapt to all funny operating system<br>
functions:<br>
<br>
* from seconds: C int<br>
* from nanoseconds: C long long<br>
* from seconds: Python float or int<br>
* from milliseconds: Python float or int<br>
* to seconds: C double<br>
* to milliseconds: _PyTime_t<br>
* to microseconds: _PyTime_t<br>
* to nanoseconds: Python int<br>
* to timeval (struct timeval)<br>
* to timeval (time_t seconds, int us)<br>
* to timespec (struct timespec)<br>
<br>
At the end, I think that it's better to only provide the "master type"<br>
at the Python level, so nanoseconds as Python int. You can *easily*<br>
implement your API on top of the PEP 564. You will be limited to<br>
nanosecond resolution, but in practice, all clocks are already limited<br>
to this resolution through operating system APIs:<br>
<a href="https://www.python.org/dev/peps/pep-0564/#sub-nanosecond-resolution" rel="noreferrer" target="_blank">https://www.python.org/dev/<wbr>peps/pep-0564/#sub-nanosecond-<wbr>resolution</a><br>
<div class="HOEnZb"><div class="h5"><br>
Victor<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>