Sleep and timedelta Was: Boolean parameters guidelines

On Wed, May 11, 2016 at 4:36 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
FWIW, I would not mind seeing sleep() as a timedelta instance method:
timedelta(seconds=42).sleep()

On 12.05.2016 02:16, Alexander Belopolsky wrote:
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

See also the PEP 410 which is somehow related: http://legacy.python.org/dev/peps/pep-0410/ (and maybe also the PEP 418) Victor

On 12.05.2016 02:16, Alexander Belopolsky wrote:
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

See also the PEP 410 which is somehow related: http://legacy.python.org/dev/peps/pep-0410/ (and maybe also the PEP 418) Victor
participants (3)
-
Alexander Belopolsky
-
Sven R. Kunze
-
Victor Stinner