Skip to content

Commit 1fd9066

Browse files
shadchin1st1
authored andcommitted
Fix TypeError('cancel() takes exactly one argument (2 given)') with Python 3.9
1 parent 3be8967 commit 1fd9066

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Diff for: uvloop/loop.pyx

+21-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ include "includes/stdlib.pxi"
4848
include "errors.pyx"
4949

5050
cdef:
51+
int PY39 = PY_VERSION_HEX >= 0x03090000
5152
int PY37 = PY_VERSION_HEX >= 0x03070000
5253
int PY36 = PY_VERSION_HEX >= 0x03060000
5354
uint64_t MAX_SLEEP = 3600 * 24 * 365 * 100
@@ -3190,12 +3191,20 @@ class _SyncSocketReaderFuture(aio_Future):
31903191
self.__sock = sock
31913192
self.__loop = loop
31923193

3193-
def cancel(self):
3194+
def __remove_reader(self):
31943195
if self.__sock is not None and self.__sock.fileno() != -1:
31953196
self.__loop.remove_reader(self.__sock)
31963197
self.__sock = None
31973198

3198-
aio_Future.cancel(self)
3199+
if PY39:
3200+
def cancel(self, msg=None):
3201+
self.__remove_reader()
3202+
aio_Future.cancel(self, msg=msg)
3203+
3204+
else:
3205+
def cancel(self):
3206+
self.__remove_reader()
3207+
aio_Future.cancel(self)
31993208

32003209

32013210
class _SyncSocketWriterFuture(aio_Future):
@@ -3205,12 +3214,20 @@ class _SyncSocketWriterFuture(aio_Future):
32053214
self.__sock = sock
32063215
self.__loop = loop
32073216

3208-
def cancel(self):
3217+
def __remove_writer(self):
32093218
if self.__sock is not None and self.__sock.fileno() != -1:
32103219
self.__loop.remove_writer(self.__sock)
32113220
self.__sock = None
32123221

3213-
aio_Future.cancel(self)
3222+
if PY39:
3223+
def cancel(self, msg=None):
3224+
self.__remove_writer()
3225+
aio_Future.cancel(self, msg=msg)
3226+
3227+
else:
3228+
def cancel(self):
3229+
self.__remove_writer()
3230+
aio_Future.cancel(self)
32143231

32153232

32163233
include "cbhandles.pyx"

0 commit comments

Comments
 (0)