[Python-ideas] Sleep and timedelta Was: Boolean parameters guidelines

Sven R. Kunze srkunze at mail.de
Thu May 12 04:36:16 EDT 2016


On 12.05.2016 02:16, Alexander Belopolsky wrote:
>
> On Wed, May 11, 2016 at 4:36 PM, Ian Kelly <ian.g.kelly at gmail.com 
> <mailto:ian.g.kelly at gmail.com>> wrote:
>
>     Still best to be explicit:
>
>     >>> sleep(timedelta(100))
>
>     It would be awesome if that actually worked.
>
>
> FWIW, I would not mind seeing sleep() as a timedelta instance method:
>
> >>> timedelta(seconds=42).sleep()

Some would suggest that introducing a new protocol like

- timedelta(seconds=42).__seconds__

defining an ABC

- class SecondLike(abc.ABC):
-     @abc.abstractmethod
-     def __seconds__(self):
-         raise NotImplementedError

defining an extraction function

- def os.seconds...

and let all stdlib functions which accepts integer/float seconds also 
accept SecondLike objects as the solution to the problem.


I have to admit that I like your idea more.


Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160512/f768c6f0/attachment-0001.html>


More information about the Python-ideas mailing list