Add socket enum classes from py3.4+#1121
Conversation
Adds four IntEnum classes in the socket module that mirror the AF_, AI_, MSG_, and SOCK_ sets of constants.
|
Running |
|
What version of mypy did you have installed for that test? |
|
I used |
|
Can you try again with mypy master? |
|
Yep, that resolved the errors! |
stdlib/3/socket.pyi
Outdated
|
|
||
| # enum versions of above flags py 3.4+ | ||
| if sys.version_info >= (3, 4): | ||
| class AddressInfo(IntEnum): |
There was a problem hiding this comment.
This one and MsgFlag actually inherit from IntFlags.
There was a problem hiding this comment.
Good point, I'll update the pull request.
stdlib/3/socket.pyi
Outdated
| # enum versions of above flags py 3.4+ | ||
| if sys.version_info >= (3, 4): | ||
| class AddressInfo(IntEnum): | ||
| AI_ADDRCONFIG = ... |
There was a problem hiding this comment.
Confirmed locally that you don't need types for the values, at least with mypy. (So no action required from you.)
|
Please wait with merging until I've tested this against our internal codebase. |
|
Is there any progress on testing? I updated the PR with fixes for @JelleZijlstra's comments and only include |
|
The tests with internal codebase pass, so +1 from me. I'll let Jelle decide whether he's happy with the rest. |
|
I'll take another look within a few days (tonight if I have time) and then merge. |
The Pull Request python#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. 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.
The Pull Request python#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. 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.
The Pull Request python#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.
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.
Adds four IntEnum classes in the socket module that mirror the
AF_, AI_, MSG_, and SOCK_ sets of constants.