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

@@ -7,31 +7,31 @@
import sys
from typing import (
List, Iterator, overload, Callable, Tuple, Sequence, Dict,
Generic, AnyStr, Match, Pattern, Any, Optional, Union
List, Iterator, overload, Callable, Tuple,
AnyStr, Match, Pattern, Any, Optional, Union
)
# ----- re variables and constants -----
if sys.version_info >= (3, 6):
import enum
class RegexFlag(enum.IntFlag):
A = 0
ASCII = 0
DEBUG = 0
I = 0
IGNORECASE = 0
L = 0
LOCALE = 0
M = 0
MULTILINE = 0
S = 0
DOTALL = 0
X = 0
VERBOSE = 0
U = 0
UNICODE = 0
T = 0
TEMPLATE = 0
A: int
ASCII: int
DEBUG: int
I: int
IGNORECASE: int
L: int
LOCALE: int
M: int
MULTILINE: int
S: int
DOTALL: int
X: int
VERBOSE: int
U: int
UNICODE: int
T: int
TEMPLATE: int
A = RegexFlag.A
ASCII = RegexFlag.ASCII
@@ -52,23 +52,23 @@ if sys.version_info >= (3, 6):
TEMPLATE = RegexFlag.TEMPLATE
_FlagsType = Union[int, RegexFlag]
else:
A = 0
ASCII = 0
DEBUG = 0
I = 0
IGNORECASE = 0
L = 0
LOCALE = 0
M = 0
MULTILINE = 0
S = 0
DOTALL = 0
X = 0
VERBOSE = 0
U = 0
UNICODE = 0
T = 0
TEMPLATE = 0
A: int
ASCII: int
DEBUG: int
I: int
IGNORECASE: int
L: int
LOCALE: int
M: int
MULTILINE: int
S: int
DOTALL: int
X: int
VERBOSE: int
U: int
UNICODE: int
T: int
TEMPLATE: int
_FlagsType = int
if sys.version_info < (3, 7):