From 4e97f21ffe5d49330d44e2f7a2598c0d1a6bc3fb Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 29 Dec 2021 08:20:10 +0100 Subject: [PATCH] Update mypy hook to v0.930 Change-Id: Ib0af7861373a537be63f75ae748722337288f6f0 --- .pre-commit-config.yaml | 4 ++-- tobiko/common/_proxy.py | 24 ++++++++++++------------ tobiko/shell/sh/_command.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26895879b..2e8614973 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,11 +34,11 @@ repos: files: ^tobiko/ - repo: https://github.com/pre-commit/mirrors-mypy.git - rev: 'v0.812' + rev: 'v0.930' hooks: - id: mypy files: ^tobiko/ - entry: mypy tobiko/ + entry: mypy --install-types --non-interactive tobiko/ pass_filenames: false # args: [--ignore-missing-imports] diff --git a/tobiko/common/_proxy.py b/tobiko/common/_proxy.py index 0f833750d..b52e4135a 100644 --- a/tobiko/common/_proxy.py +++ b/tobiko/common/_proxy.py @@ -20,7 +20,7 @@ import typing import decorator -def protocol(cls: type) -> type: +def protocol(cls: typing.Type) -> typing.Type: name = cls.__name__ bases = inspect.getmro(cls)[1:] namespace = dict(cls.__dict__, @@ -29,8 +29,8 @@ def protocol(cls: type) -> type: return type(name, bases, namespace) -def is_protocol_class(cls): - return inspect.isclass(cls) and cls.__dict__.get('_is_protocol', False) +def is_protocol_class(obj): + return inspect.isclass(obj) and obj.__dict__.get('_is_protocol', False) def is_public_function(obj): @@ -53,7 +53,7 @@ class CallHandlerMeta(type): class CallHandler(metaclass=CallHandlerMeta): - protocol_class: type + protocol_class: typing.Type def __init__(self, handle_call: typing.Optional[typing.Callable] = None): @@ -70,16 +70,16 @@ class CallHandler(metaclass=CallHandlerMeta): def call_proxy_class( - cls: type, - *bases: type, - class_name: typing.Optional[str] = None, - namespace: typing.Optional[dict] = None) \ - -> type: + cls: typing.Type, + *bases: typing.Type, + class_name: str = None, + namespace: dict = None) \ + -> typing.Type: if not inspect.isclass(cls): raise TypeError(f"Object {cls} is not a class") if class_name is None: class_name = cls.__name__ + 'Proxy' - protocol_classes = list_protocols(cls) + protocol_classes = list_protocols(typing.cast(typing.Hashable, cls)) if not protocol_classes: raise TypeError(f"Class {cls} doesn't implement any protocol") if namespace is None: @@ -99,13 +99,13 @@ def call_proxy_class( return proxy_class -def call_proxy(cls: type, handle_call: typing.Callable) -> CallHandler: +def call_proxy(cls: typing.Type, handle_call: typing.Callable) -> CallHandler: proxy_class = call_proxy_class(cls, CallHandler) return proxy_class(handle_call) @functools.lru_cache() -def list_protocols(cls: type) -> typing.Tuple[type, ...]: +def list_protocols(cls: typing.Type) -> typing.Tuple[typing.Type, ...]: subclasses = inspect.getmro(cls) protocols = tuple(cls for cls in subclasses diff --git a/tobiko/shell/sh/_command.py b/tobiko/shell/sh/_command.py index f45e2dd0d..7992f5b23 100644 --- a/tobiko/shell/sh/_command.py +++ b/tobiko/shell/sh/_command.py @@ -20,7 +20,7 @@ import shlex import typing -ShellCommandType = typing.Union['ShellCommand', str, typing.Iterable[str]] +ShellCommandType = typing.Union['ShellCommand', str, typing.Iterable] class ShellCommand(tuple):