From d2878166df9bc5c6f9ea86587876d571daab28ec Mon Sep 17 00:00:00 2001 From: pollenJP Date: Sun, 23 Jan 2022 07:39:09 +0900 Subject: [PATCH] Bugfix/modify mypy ci (#789) * Fix: mypy fatal errors (error: Invalid "type: ignore" comment) * Add mypy.ini - ignore_errors * Fix mypy ci returning always true * Fix typo --- .github/workflows/mypy.yml | 2 +- discord/commands/core.py | 10 +++++----- mypy.ini | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 mypy.ini diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index f4632f3354..dfbbf8650d 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -9,4 +9,4 @@ jobs: - run: pip install mypy - run: pip install -r requirements.txt - run: mkdir --parents --verbose .mypy_cache - - run: mypy --ignore-missing-imports --install-types --non-interactive . || true + - run: mypy --ignore-missing-imports --install-types --non-interactive . diff --git a/discord/commands/core.py b/discord/commands/core.py index 8b3968694d..7ae6f152a0 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -164,7 +164,7 @@ async def __call__(self, ctx, *args, **kwargs): def _prepare_cooldowns(self, ctx: ApplicationContext): if self._buckets.valid: current = datetime.datetime.now().timestamp() - bucket = self._buckets.get_bucket(ctx, current) # type: ignore (ctx instead of non-existent message) + bucket = self._buckets.get_bucket(ctx, current) # type: ignore # ctx instead of non-existent message if bucket is not None: retry_after = bucket.update_rate_limit(current) @@ -183,14 +183,14 @@ async def prepare(self, ctx: ApplicationContext) -> None: if hasattr(self, "_max_concurrency"): if self._max_concurrency is not None: # For this application, context can be duck-typed as a Message - await self._max_concurrency.acquire(ctx) # type: ignore (ctx instead of non-existent message) + await self._max_concurrency.acquire(ctx) # type: ignore # ctx instead of non-existent message try: self._prepare_cooldowns(ctx) await self.call_before_hooks(ctx) except: if self._max_concurrency is not None: - await self._max_concurrency.release(ctx) # type: ignore (ctx instead of non-existent message) + await self._max_concurrency.release(ctx) # type: ignore # ctx instead of non-existent message raise def is_on_cooldown(self, ctx: ApplicationContext) -> bool: @@ -226,7 +226,7 @@ def reset_cooldown(self, ctx: ApplicationContext) -> None: The invocation context to reset the cooldown under. """ if self._buckets.valid: - bucket = self._buckets.get_bucket(ctx) # type: ignore (ctx instead of non-existent message) + bucket = self._buckets.get_bucket(ctx) # type: ignore # ctx instead of non-existent message bucket.reset() def get_cooldown_retry_after(self, ctx: ApplicationContext) -> float: @@ -630,7 +630,7 @@ def _match_option_param_names(self, params, options): check_annotations = [ lambda o, a: o.input_type == SlashCommandOptionType.string and o.converter is not None, # pass on converters lambda o, a: isinstance(o.input_type, SlashCommandOptionType), # pass on slash cmd option type enums - lambda o, a: isinstance(o._raw_type, tuple) and a == Union[o._raw_type], # type: ignore (union types) + lambda o, a: isinstance(o._raw_type, tuple) and a == Union[o._raw_type], # type: ignore # union types lambda o, a: self._is_typing_optional(a) and not o.required and o._raw_type in a.__args__, # optional lambda o, a: inspect.isclass(a) and issubclass(a, o._raw_type) # 'normal' types ] diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000000..fdd12d1492 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,2 @@ +[mypy] +ignore_errors = True