Skip to content

Commit

Permalink
Add precise values for enum members where possible (#11299)
Browse files Browse the repository at this point in the history
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent b3bfbef commit 17f1c46
Show file tree
Hide file tree
Showing 36 changed files with 1,093 additions and 1,087 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ extend-ignore = Y090
per-file-ignores =
# We should only need to noqa Y and F821 codes in .pyi files
*.py: NQA
# Ignore Y052 in this file: there are loads of false positives
# due to the fact that flake8-pyi doesn't understand subclasses of `CoerciveEnum`
# as being enum classes
stubs/fpdf2/fpdf/enums.pyi: Y052
# Generated protobuf files:
# Y021: Include docstrings
# Y023: Alias typing as typing_extensions
Expand Down
6 changes: 3 additions & 3 deletions stdlib/asyncio/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ if sys.version_info >= (3, 12):
THREAD_JOIN_TIMEOUT: Literal[300]

class _SendfileMode(enum.Enum):
UNSUPPORTED: int
TRY_NATIVE: int
FALLBACK: int
UNSUPPORTED = 1
TRY_NATIVE = 2
FALLBACK = 3
8 changes: 4 additions & 4 deletions stdlib/asyncio/locks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ class BoundedSemaphore(Semaphore): ...

if sys.version_info >= (3, 11):
class _BarrierState(enum.Enum): # undocumented
FILLING: str
DRAINING: str
RESETTING: str
BROKEN: str
FILLING = "filling"
DRAINING = "draining"
RESETTING = "resetting"
BROKEN = "broken"

class Barrier(_LoopBoundMixin):
def __init__(self, parties: int) -> None: ...
Expand Down
18 changes: 9 additions & 9 deletions stdlib/asyncio/sslproto.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ if sys.version_info >= (3, 11):
SSLAgainErrors: tuple[type[ssl.SSLWantReadError], type[ssl.SSLSyscallError]]

class SSLProtocolState(Enum):
UNWRAPPED: str
DO_HANDSHAKE: str
WRAPPED: str
FLUSHING: str
SHUTDOWN: str
UNWRAPPED = "UNWRAPPED"
DO_HANDSHAKE = "DO_HANDSHAKE"
WRAPPED = "WRAPPED"
FLUSHING = "FLUSHING"
SHUTDOWN = "SHUTDOWN"

class AppProtocolState(Enum):
STATE_INIT: str
STATE_CON_MADE: str
STATE_EOF: str
STATE_CON_LOST: str
STATE_INIT = "STATE_INIT"
STATE_CON_MADE = "STATE_CON_MADE"
STATE_EOF = "STATE_EOF"
STATE_CON_LOST = "STATE_CON_LOST"

def add_flowcontrol_defaults(high: int | None, low: int | None, kb: int) -> tuple[int, int]: ...

Expand Down
136 changes: 68 additions & 68 deletions stdlib/http/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,65 @@ class HTTPStatus(IntEnum):
def phrase(self) -> str: ...
@property
def description(self) -> str: ...
CONTINUE: int
SWITCHING_PROTOCOLS: int
PROCESSING: int
OK: int
CREATED: int
ACCEPTED: int
NON_AUTHORITATIVE_INFORMATION: int
NO_CONTENT: int
RESET_CONTENT: int
PARTIAL_CONTENT: int
MULTI_STATUS: int
ALREADY_REPORTED: int
IM_USED: int
MULTIPLE_CHOICES: int
MOVED_PERMANENTLY: int
FOUND: int
SEE_OTHER: int
NOT_MODIFIED: int
USE_PROXY: int
TEMPORARY_REDIRECT: int
PERMANENT_REDIRECT: int
BAD_REQUEST: int
UNAUTHORIZED: int
PAYMENT_REQUIRED: int
FORBIDDEN: int
NOT_FOUND: int
METHOD_NOT_ALLOWED: int
NOT_ACCEPTABLE: int
PROXY_AUTHENTICATION_REQUIRED: int
REQUEST_TIMEOUT: int
CONFLICT: int
GONE: int
LENGTH_REQUIRED: int
PRECONDITION_FAILED: int
REQUEST_ENTITY_TOO_LARGE: int
REQUEST_URI_TOO_LONG: int
UNSUPPORTED_MEDIA_TYPE: int
REQUESTED_RANGE_NOT_SATISFIABLE: int
EXPECTATION_FAILED: int
UNPROCESSABLE_ENTITY: int
LOCKED: int
FAILED_DEPENDENCY: int
UPGRADE_REQUIRED: int
PRECONDITION_REQUIRED: int
TOO_MANY_REQUESTS: int
REQUEST_HEADER_FIELDS_TOO_LARGE: int
INTERNAL_SERVER_ERROR: int
NOT_IMPLEMENTED: int
BAD_GATEWAY: int
SERVICE_UNAVAILABLE: int
GATEWAY_TIMEOUT: int
HTTP_VERSION_NOT_SUPPORTED: int
VARIANT_ALSO_NEGOTIATES: int
INSUFFICIENT_STORAGE: int
LOOP_DETECTED: int
NOT_EXTENDED: int
NETWORK_AUTHENTICATION_REQUIRED: int
MISDIRECTED_REQUEST: int
UNAVAILABLE_FOR_LEGAL_REASONS: int
CONTINUE = 100
SWITCHING_PROTOCOLS = 101
PROCESSING = 102
OK = 200
CREATED = 201
ACCEPTED = 202
NON_AUTHORITATIVE_INFORMATION = 203
NO_CONTENT = 204
RESET_CONTENT = 205
PARTIAL_CONTENT = 206
MULTI_STATUS = 207
ALREADY_REPORTED = 208
IM_USED = 226
MULTIPLE_CHOICES = 300
MOVED_PERMANENTLY = 301
FOUND = 302
SEE_OTHER = 303
NOT_MODIFIED = 304
USE_PROXY = 305
TEMPORARY_REDIRECT = 307
PERMANENT_REDIRECT = 308
BAD_REQUEST = 400
UNAUTHORIZED = 401
PAYMENT_REQUIRED = 402
FORBIDDEN = 403
NOT_FOUND = 404
METHOD_NOT_ALLOWED = 405
NOT_ACCEPTABLE = 406
PROXY_AUTHENTICATION_REQUIRED = 407
REQUEST_TIMEOUT = 408
CONFLICT = 409
GONE = 410
LENGTH_REQUIRED = 411
PRECONDITION_FAILED = 412
REQUEST_ENTITY_TOO_LARGE = 413
REQUEST_URI_TOO_LONG = 414
UNSUPPORTED_MEDIA_TYPE = 415
REQUESTED_RANGE_NOT_SATISFIABLE = 416
EXPECTATION_FAILED = 417
UNPROCESSABLE_ENTITY = 422
LOCKED = 423
FAILED_DEPENDENCY = 424
UPGRADE_REQUIRED = 426
PRECONDITION_REQUIRED = 428
TOO_MANY_REQUESTS = 429
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
INTERNAL_SERVER_ERROR = 500
NOT_IMPLEMENTED = 501
BAD_GATEWAY = 502
SERVICE_UNAVAILABLE = 503
GATEWAY_TIMEOUT = 504
HTTP_VERSION_NOT_SUPPORTED = 505
VARIANT_ALSO_NEGOTIATES = 506
INSUFFICIENT_STORAGE = 507
LOOP_DETECTED = 508
NOT_EXTENDED = 510
NETWORK_AUTHENTICATION_REQUIRED = 511
MISDIRECTED_REQUEST = 421
UNAVAILABLE_FOR_LEGAL_REASONS = 451
if sys.version_info >= (3, 9):
EARLY_HINTS: Literal[103]
IM_A_TEAPOT: Literal[418]
Expand All @@ -94,12 +94,12 @@ if sys.version_info >= (3, 11):
class HTTPMethod(StrEnum):
@property
def description(self) -> str: ...
CONNECT: str
DELETE: str
GET: str
HEAD: str
OPTIONS: str
PATCH: str
POST: str
PUT: str
TRACE: str
CONNECT = "CONNECT"
DELETE = "DELETE"
GET = "GET"
HEAD = "HEAD"
OPTIONS = "OPTIONS"
PATCH = "PATCH"
POST = "POST"
PUT = "PUT"
TRACE = "TRACE"
48 changes: 24 additions & 24 deletions stdlib/inspect.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ if sys.version_info >= (3, 10):

# The name is the same as the enum's name in CPython
class _ParameterKind(enum.IntEnum):
POSITIONAL_ONLY: int
POSITIONAL_OR_KEYWORD: int
VAR_POSITIONAL: int
KEYWORD_ONLY: int
VAR_KEYWORD: int
POSITIONAL_ONLY = 0
POSITIONAL_OR_KEYWORD = 1
VAR_POSITIONAL = 2
KEYWORD_ONLY = 3
VAR_KEYWORD = 4

@property
def description(self) -> str: ...
Expand Down Expand Up @@ -611,22 +611,22 @@ if sys.version_info >= (3, 9):

if sys.version_info >= (3, 12):
class BufferFlags(enum.IntFlag):
SIMPLE: int
WRITABLE: int
FORMAT: int
ND: int
STRIDES: int
C_CONTIGUOUS: int
F_CONTIGUOUS: int
ANY_CONTIGUOUS: int
INDIRECT: int
CONTIG: int
CONTIG_RO: int
STRIDED: int
STRIDED_RO: int
RECORDS: int
RECORDS_RO: int
FULL: int
FULL_RO: int
READ: int
WRITE: int
SIMPLE = 0
WRITABLE = 1
FORMAT = 4
ND = 8
STRIDES = 24
C_CONTIGUOUS = 56
F_CONTIGUOUS = 88
ANY_CONTIGUOUS = 152
INDIRECT = 280
CONTIG = 9
CONTIG_RO = 8
STRIDED = 25
STRIDED_RO = 24
RECORDS = 29
RECORDS_RO = 28
FULL = 285
FULL_RO = 284
READ = 256
WRITE = 512
4 changes: 2 additions & 2 deletions stdlib/plistlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ if sys.version_info < (3, 9):
__all__ += ["readPlist", "writePlist", "readPlistFromBytes", "writePlistToBytes", "Data"]

class PlistFormat(Enum):
FMT_XML: int
FMT_BINARY: int
FMT_XML = 1
FMT_BINARY = 2

FMT_XML = PlistFormat.FMT_XML
FMT_BINARY = PlistFormat.FMT_BINARY
Expand Down
18 changes: 9 additions & 9 deletions stdlib/pstats.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ else:
_Selector: TypeAlias = str | float | int

class SortKey(StrEnum):
CALLS: str
CUMULATIVE: str
FILENAME: str
LINE: str
NAME: str
NFL: str
PCALLS: str
STDNAME: str
TIME: str
CALLS = "calls"
CUMULATIVE = "cumulative"
FILENAME = "filename"
LINE = "line"
NAME = "name"
NFL = "nfl"
PCALLS = "pcalls"
STDNAME = "stdname"
TIME = "time"

if sys.version_info >= (3, 9):
from dataclasses import dataclass
Expand Down
6 changes: 3 additions & 3 deletions stdlib/py_compile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class PyCompileError(Exception):
def __init__(self, exc_type: type[BaseException], exc_value: BaseException, file: str, msg: str = "") -> None: ...

class PycInvalidationMode(enum.Enum):
TIMESTAMP: int
CHECKED_HASH: int
UNCHECKED_HASH: int
TIMESTAMP = 1
CHECKED_HASH = 2
UNCHECKED_HASH = 3

def _get_default_invalidation_mode() -> PycInvalidationMode: ...
def compile(
Expand Down
Loading

0 comments on commit 17f1c46

Please sign in to comment.