Improve enums (#3168)

I realized while working on srittau/type-stub-pep#64 that a
few things we do in existing enum definitions in typeshed are
problematic:

- Using "= ..." doesn't allow type checkers to correctly type the
  result of Enum.MEMBER.value. In fact, mypy at least infers
  .value to be "Ellipsis" if you do this.
- Properties on the enum values themselves, like HTTPStatus.phrase,
  should not be specified directly as attributes, because it makes
  type checkers think that the properties themselves are enum
  members.

I ended up doing a bit more cleanup to the signal module:
- Remove unnecessary ... initializers.
- Remove unnecessary _SIG = Signals alias.
- I don't have Windows to test, but the C code for _signal suggests
  that CTRL_C_EVENT and CTRL_BREAK events are not Signals, but just ints:
  1dbd084f1f/Modules/signalmodule.c (L1575)
This commit is contained in:
Jelle Zijlstra
2019-08-05 08:08:57 -07:00
committed by GitHub
parent 1dc24e1c67
commit d05a9d3d83
5 changed files with 239 additions and 243 deletions

View File

@@ -411,45 +411,45 @@ if sys.version_info >= (3, 4):
from enum import IntEnum
class AddressFamily(IntEnum):
AF_UNIX = ...
AF_INET = ...
AF_INET6 = ...
AF_APPLETALK = ...
AF_ASH = ...
AF_ATMPVC = ...
AF_ATMSVC = ...
AF_AX25 = ...
AF_BLUETOOTH = ...
AF_BRIDGE = ...
AF_DECnet = ...
AF_ECONET = ...
AF_IPX = ...
AF_IRDA = ...
AF_KEY = ...
AF_LLC = ...
AF_NETBEUI = ...
AF_NETLINK = ...
AF_NETROM = ...
AF_PACKET = ...
AF_PPPOX = ...
AF_ROSE = ...
AF_ROUTE = ...
AF_SECURITY = ...
AF_SNA = ...
AF_TIPC = ...
AF_UNSPEC = ...
AF_WANPIPE = ...
AF_X25 = ...
AF_LINK = ...
AF_UNIX: int
AF_INET: int
AF_INET6: int
AF_APPLETALK: int
AF_ASH: int
AF_ATMPVC: int
AF_ATMSVC: int
AF_AX25: int
AF_BLUETOOTH: int
AF_BRIDGE: int
AF_DECnet: int
AF_ECONET: int
AF_IPX: int
AF_IRDA: int
AF_KEY: int
AF_LLC: int
AF_NETBEUI: int
AF_NETLINK: int
AF_NETROM: int
AF_PACKET: int
AF_PPPOX: int
AF_ROSE: int
AF_ROUTE: int
AF_SECURITY: int
AF_SNA: int
AF_TIPC: int
AF_UNSPEC: int
AF_WANPIPE: int
AF_X25: int
AF_LINK: int
class SocketKind(IntEnum):
SOCK_STREAM = ...
SOCK_DGRAM = ...
SOCK_RAW = ...
SOCK_RDM = ...
SOCK_SEQPACKET = ...
SOCK_CLOEXEC = ...
SOCK_NONBLOCK = ...
SOCK_STREAM: int
SOCK_DGRAM: int
SOCK_RAW: int
SOCK_RDM: int
SOCK_SEQPACKET: int
SOCK_CLOEXEC: int
SOCK_NONBLOCK: int
else:
AddressFamily = int
SocketKind = int
@@ -458,23 +458,23 @@ if sys.version_info >= (3, 6):
from enum import IntFlag
class AddressInfo(IntFlag):
AI_ADDRCONFIG = ...
AI_ALL = ...
AI_CANONNAME = ...
AI_NUMERICHOST = ...
AI_NUMERICSERV = ...
AI_PASSIVE = ...
AI_V4MAPPED = ...
AI_ADDRCONFIG: int
AI_ALL: int
AI_CANONNAME: int
AI_NUMERICHOST: int
AI_NUMERICSERV: int
AI_PASSIVE: int
AI_V4MAPPED: int
class MsgFlag(IntFlag):
MSG_CTRUNC = ...
MSG_DONTROUTE = ...
MSG_DONTWAIT = ...
MSG_EOR = ...
MSG_OOB = ...
MSG_PEEK = ...
MSG_TRUNC = ...
MSG_WAITALL = ...
MSG_CTRUNC: int
MSG_DONTROUTE: int
MSG_DONTWAIT: int
MSG_EOR: int
MSG_OOB: int
MSG_PEEK: int
MSG_TRUNC: int
MSG_WAITALL: int
else:
AddressInfo = int
MsgFlag = int