From 1a314a035848dafac8f334c7536632581ca08dab Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:40:28 -0700 Subject: [PATCH] Update enums to reflect typing spec changes (#1020) * Update enums to reflect typing spec changes See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members https://github.com/python/typing-council/issues/11 The next version of mypy will obey the spec change: https://github.com/python/mypy/pull/18068 pyright already requires this * warning * . * . --- pandas-stubs/_libs/tslibs/dtypes.pyi | 21 +++++----- .../core/interchange/dataframe_protocol.pyi | 41 ++++++++++--------- scripts/__init__.py | 3 +- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/pandas-stubs/_libs/tslibs/dtypes.pyi b/pandas-stubs/_libs/tslibs/dtypes.pyi index 786a156bf..7d0a43ab2 100644 --- a/pandas-stubs/_libs/tslibs/dtypes.pyi +++ b/pandas-stubs/_libs/tslibs/dtypes.pyi @@ -1,4 +1,5 @@ from enum import Enum +from typing import cast from .offsets import BaseOffset @@ -29,16 +30,16 @@ class FreqGroup: def get_freq_group(code: int) -> int: ... class Resolution(Enum): - RESO_NS: int - RESO_US: int - RESO_MS: int - RESO_SEC: int - RESO_MIN: int - RESO_HR: int - RESO_DAY: int - RESO_MTH: int - RESO_QTR: int - RESO_YR: int + RESO_NS = cast(int, ...) + RESO_US = cast(int, ...) + RESO_MS = cast(int, ...) + RESO_SEC = cast(int, ...) + RESO_MIN = cast(int, ...) + RESO_HR = cast(int, ...) + RESO_DAY = cast(int, ...) + RESO_MTH = cast(int, ...) + RESO_QTR = cast(int, ...) + RESO_YR = cast(int, ...) def __lt__(self, other) -> bool: ... def __ge__(self, other) -> bool: ... diff --git a/pandas-stubs/core/interchange/dataframe_protocol.pyi b/pandas-stubs/core/interchange/dataframe_protocol.pyi index 8d6052068..a29c573cc 100644 --- a/pandas-stubs/core/interchange/dataframe_protocol.pyi +++ b/pandas-stubs/core/interchange/dataframe_protocol.pyi @@ -11,33 +11,34 @@ import enum from typing import ( Any, TypedDict, + cast, ) class DlpackDeviceType(enum.IntEnum): - CPU: int - CUDA: int - CPU_PINNED: int - OPENCL: int - VULKAN: int - METAL: int - VPI: int - ROCM: int + CPU = cast(int, ...) + CUDA = cast(int, ...) + CPU_PINNED = cast(int, ...) + OPENCL = cast(int, ...) + VULKAN = cast(int, ...) + METAL = cast(int, ...) + VPI = cast(int, ...) + ROCM = cast(int, ...) class DtypeKind(enum.IntEnum): - INT: int - UINT: int - FLOAT: int - BOOL: int - STRING: int - DATETIME: int - CATEGORICAL: int + INT = cast(int, ...) + UINT = cast(int, ...) + FLOAT = cast(int, ...) + BOOL = cast(int, ...) + STRING = cast(int, ...) + DATETIME = cast(int, ...) + CATEGORICAL = cast(int, ...) class ColumnNullType(enum.IntEnum): - NON_NULLABLE: int - USE_NAN: int - USE_SENTINEL: int - USE_BITMASK: int - USE_BYTEMASK: int + NON_NULLABLE = cast(int, ...) + USE_NAN = cast(int, ...) + USE_SENTINEL = cast(int, ...) + USE_BITMASK = cast(int, ...) + USE_BYTEMASK = cast(int, ...) class ColumnBuffers(TypedDict): data: tuple[Buffer, Any] diff --git a/scripts/__init__.py b/scripts/__init__.py index 5d4942219..40a12223b 100644 --- a/scripts/__init__.py +++ b/scripts/__init__.py @@ -1,9 +1,10 @@ import sys +from typing import Any from loguru import logger # Config the format of log message -config = { +config: dict[str, Any] = { "handlers": [ { "sink": sys.stderr,