Always consume the no_throttle keyword argument. (#11126)

The current code relies on the assumption that the first invocation will never specify no_throttle=True.
However that puts us in a pickle when writing unit tests: if we had a fictitious:

  def setup_platform():
    update()

  @Throttle(MIN_TIME_BETWEEN_SCANS)
  def update():
    pass

Then given multiple tests, the second and some of subsequent tests would be throttled (depending on timing).
But we also can't change that code to call `update(no_throttle=True)' because that's not currently accepted.

This diff shouldn't change the visibile behavior of any component, but allows this extra flexibility.
pull/11136/head
Andrea Campi 2017-12-14 04:01:59 +00:00 committed by Paulus Schoutsen
parent d547345f90
commit e627544479
1 changed files with 1 additions and 1 deletions

View File

@ -299,7 +299,7 @@ class Throttle(object):
return None return None
# Check if method is never called or no_throttle is given # Check if method is never called or no_throttle is given
force = not throttle[1] or kwargs.pop('no_throttle', False) force = kwargs.pop('no_throttle', False) or not throttle[1]
try: try:
if force or utcnow() - throttle[1] > self.min_time: if force or utcnow() - throttle[1] > self.min_time: