@@ -489,11 +489,22 @@ cdef class Loop:
489489 self ._polls_gc[fd] = poll
490490 return result
491491
492- cdef _getaddrinfo(self , str host, int port,
492+ cdef _getaddrinfo(self , object host, object port,
493493 int family, int type ,
494494 int proto, int flags,
495495 int unpack):
496496
497+ if isinstance (port, str ):
498+ port = port.encode()
499+ elif isinstance (port, int ):
500+ port = str (port).encode()
501+ if not isinstance (port, bytes):
502+ raise TypeError (' port must be a str, bytes or int' )
503+ if isinstance (host, str ):
504+ host = host.encode()
505+ if not isinstance (host, bytes):
506+ raise TypeError (' host must be a str or bytes' )
507+
497508 fut = self ._new_future()
498509
499510 def callback (result ):
@@ -895,7 +906,7 @@ cdef class Loop:
895906
896907 return future.result()
897908
898- def getaddrinfo (self , str host , int port , *,
909+ def getaddrinfo (self , object host , object port , *,
899910 int family = 0 , int type = 0 , int proto = 0 , int flags = 0 ):
900911
901912 return self ._getaddrinfo(host, port, family, type , proto, flags, 1 )
@@ -915,14 +926,6 @@ cdef class Loop:
915926 if sl < 2 or sl > 4 :
916927 raise ValueError (' sockaddr must be a tuple of 2, 3 or 4 values' )
917928
918- host = sockaddr[0 ]
919- if not isinstance (host, str ):
920- raise TypeError (' host must be a string' )
921-
922- port = sockaddr[1 ]
923- if not isinstance (port, int ):
924- raise TypeError (' port must be an int' )
925-
926929 if sl > 2 :
927930 flowinfo = sockaddr[2 ]
928931 if flowinfo < 0 or flowinfo > 0xfffff :
@@ -940,7 +943,7 @@ cdef class Loop:
940943 scope_id = 0
941944
942945 ai_cnt = await self ._getaddrinfo(
943- host, port ,
946+ sockaddr[ 0 ], sockaddr[ 1 ] ,
944947 uv.AF_UNSPEC, # family
945948 uv.SOCK_DGRAM, # type
946949 0 , # proto
0 commit comments