Skip to content

Commit

Permalink
Fix TypeError('cancel() takes exactly one argument (2 given)') with P…
Browse files Browse the repository at this point in the history
…ython 3.9
  • Loading branch information
shadchin authored and 1st1 committed Dec 7, 2020
1 parent 3be8967 commit 1fd9066
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ include "includes/stdlib.pxi"
include "errors.pyx"

cdef:
int PY39 = PY_VERSION_HEX >= 0x03090000
int PY37 = PY_VERSION_HEX >= 0x03070000
int PY36 = PY_VERSION_HEX >= 0x03060000
uint64_t MAX_SLEEP = 3600 * 24 * 365 * 100
Expand Down Expand Up @@ -3190,12 +3191,20 @@ class _SyncSocketReaderFuture(aio_Future):
self.__sock = sock
self.__loop = loop

def cancel(self):
def __remove_reader(self):
if self.__sock is not None and self.__sock.fileno() != -1:
self.__loop.remove_reader(self.__sock)
self.__sock = None

aio_Future.cancel(self)
if PY39:
def cancel(self, msg=None):
self.__remove_reader()
aio_Future.cancel(self, msg=msg)

else:
def cancel(self):
self.__remove_reader()
aio_Future.cancel(self)


class _SyncSocketWriterFuture(aio_Future):
Expand All @@ -3205,12 +3214,20 @@ class _SyncSocketWriterFuture(aio_Future):
self.__sock = sock
self.__loop = loop

def cancel(self):
def __remove_writer(self):
if self.__sock is not None and self.__sock.fileno() != -1:
self.__loop.remove_writer(self.__sock)
self.__sock = None

aio_Future.cancel(self)
if PY39:
def cancel(self, msg=None):
self.__remove_writer()
aio_Future.cancel(self, msg=msg)

else:
def cancel(self):
self.__remove_writer()
aio_Future.cancel(self)


include "cbhandles.pyx"
Expand Down

0 comments on commit 1fd9066

Please sign in to comment.