Commits

Jason R. Coombs committed ecc127a

Stopwatch context now returns self

  • Participants
  • Parent commits 439e129
  • Tags 8.2

Comments (0)

Files changed (2)

 Changes
 -------
 
+8.2
+~~~
+
+* ``timing.Stopwatch`` context now returns self for convenience.
+
 8.1
 ~~~
 

File jaraco/util/timing.py

 	>>> w.start()
 	>>> w.split() < _1_sec
 	True
+
+	It should be possible to launch the Stopwatch in a context:
+
+	>>> with Stopwatch() as watch:
+	...     assert isinstance(watch.split(), datetime.timedelta)
 	"""
 	def __init__(self):
 		self.reset()
 		return self.elapsed + local_duration
 
 	# context manager support
-	__enter__ = start
+	def __enter__(self):
+		self.start()
+		return self
 
 	def __exit__(self, exc_type, exc_value, traceback):
 		self.stop()