Skip to content

Commit

Permalink
Explicitly convert float to int for startTimer
Browse files Browse the repository at this point in the history
As of Python3.10:
> Builtin and extension functions that take integer arguments no longer
accept Decimals, Fractions and other objects that can be converted to
integers only with a loss (e.g. that have the int() method but do not
have the index() method). (Contributed by Serhiy Storchaka in
bpo-37999.)

`startTimer` accepts only integers (milliseconds) and fails to
implicitly convert floats.

Fixes: harvimt#128
Signed-off-by: Stanislav Levin <slev@altlinux.org>
  • Loading branch information
stanislavlevin committed Mar 21, 2022
1 parent d9520f4 commit ad843f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion quamash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def __init__(self):
self._stopped = False

def add_callback(self, handle, delay=0):
timerid = self.startTimer(delay * 1000)
"""
delay should be in seconds(float or int), while
startTimer accepts milliseconds(int)
"""
timerid = self.startTimer(round(delay * 1000))
self._logger.debug("Registering timer id {0}".format(timerid))
assert timerid not in self.__callbacks
self.__callbacks[timerid] = handle
Expand Down

1 comment on commit ad843f3

@KlingLi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this solved my issues
thx a lot

Please sign in to comment.