From 686d6b7450368b15728b9345c5800a2ce35302da Mon Sep 17 00:00:00 2001 From: Joongi Kim Date: Sat, 18 Dec 2021 12:43:37 +0900 Subject: [PATCH] fix: Apply mypy 0.920 update (#104) * setup: Upgrade mypy to 0.920 * fix: Remove bogus type-casting * fix: Call `__init__()` as a classmethod --- changes/104.fix | 1 + setup.cfg | 2 +- src/ai/backend/common/cli.py | 4 ++-- src/ai/backend/common/types.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changes/104.fix diff --git a/changes/104.fix b/changes/104.fix new file mode 100644 index 00000000..eb79f4b0 --- /dev/null +++ b/changes/104.fix @@ -0,0 +1 @@ +Fix minor typing errors discovered by mypy 0.920 update diff --git a/setup.cfg b/setup.cfg index 25f38dc7..0af12eda 100644 --- a/setup.cfg +++ b/setup.cfg @@ -83,7 +83,7 @@ lint = flake8>=4.0.1 flake8-commas>=2.1 typecheck = - mypy>=0.910 + mypy>=0.920 types-python-dateutil types-toml types-setuptools diff --git a/src/ai/backend/common/cli.py b/src/ai/backend/common/cli.py index 415e8f20..90347b78 100644 --- a/src/ai/backend/common/cli.py +++ b/src/ai/backend/common/cli.py @@ -4,7 +4,7 @@ from importlib import import_module import re from types import FunctionType -from typing import Any, Optional, Union, Type, cast +from typing import Any, Optional, Union, Type import click @@ -58,7 +58,7 @@ class EnumChoice(click.Choice): enum: Type[Enum] def __init__(self, enum: Type[Enum]): - super().__init__([*cast(Enum, enum)._member_map_.keys()]) + super().__init__([*enum._member_map_.keys()]) self.enum = enum def convert(self, value: Any, param, ctx): diff --git a/src/ai/backend/common/types.py b/src/ai/backend/common/types.py index da063d4f..fa49473f 100644 --- a/src/ai/backend/common/types.py +++ b/src/ai/backend/common/types.py @@ -99,7 +99,7 @@ async def new(cls: Type[T_aobj], *args, **kwargs) -> T_aobj: This is a copy of ``__new__()`` to workaround it. ''' instance = super().__new__(cls) - instance.__init__(*args, **kwargs) + cls.__init__(instance, *args, **kwargs) await instance.__ainit__() return instance