From d149fe435cf3b44a4d5b0d2a4e63b8b05845f49b Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Wed, 19 Jun 2019 23:14:15 +0100 Subject: [PATCH] Represent the use of IntEnums in functions in socket.py. (#3009) The Pull Request #1121 added the `AddressFamily` type to `socket.pyi` for Python 3.4+, so constants such as `AF_INET` are correctly represented as being an enum member rather than an int. The same is true of the `SocketKind` enums in the `SOCK_*` family. Various functions in the socket module can accept either an int or an `AF_*` enum member as arguments, which is allowed by the int argument type. However the `getaddrinfo` function returns an `AddressFamily` member rather than an int in the first position of its list members, so code that access enum specific members such as the `name` attribute causes a typing error to be found. This change corrects the return type of `getaddrinfo` but leaves the family parameters as int, given that `AddressFamily` members are `IntEnum` and only ever treated as `int`s internally. --- stdlib/2and3/socket.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/2and3/socket.pyi b/stdlib/2and3/socket.pyi index 22b2f9135..4089b225c 100644 --- a/stdlib/2and3/socket.pyi +++ b/stdlib/2and3/socket.pyi @@ -590,7 +590,7 @@ def create_connection(address: Tuple[Optional[str], int], def getaddrinfo( host: Optional[Union[bytearray, bytes, Text]], port: Union[str, int, None], family: int = ..., socktype: int = ..., proto: int = ..., - flags: int = ...) -> List[Tuple[int, int, int, str, Tuple[Any, ...]]]: + flags: int = ...) -> List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]]: ... def getfqdn(name: str = ...) -> str: ...