Update mypy hook to v0.930
Change-Id: Ib0af7861373a537be63f75ae748722337288f6f0
This commit is contained in:
parent
1d25a77a33
commit
4e97f21ffe
@ -34,11 +34,11 @@ repos:
|
|||||||
files: ^tobiko/
|
files: ^tobiko/
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy.git
|
- repo: https://github.com/pre-commit/mirrors-mypy.git
|
||||||
rev: 'v0.812'
|
rev: 'v0.930'
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
files: ^tobiko/
|
files: ^tobiko/
|
||||||
entry: mypy tobiko/
|
entry: mypy --install-types --non-interactive tobiko/
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
# args: [--ignore-missing-imports]
|
# args: [--ignore-missing-imports]
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import typing
|
|||||||
import decorator
|
import decorator
|
||||||
|
|
||||||
|
|
||||||
def protocol(cls: type) -> type:
|
def protocol(cls: typing.Type) -> typing.Type:
|
||||||
name = cls.__name__
|
name = cls.__name__
|
||||||
bases = inspect.getmro(cls)[1:]
|
bases = inspect.getmro(cls)[1:]
|
||||||
namespace = dict(cls.__dict__,
|
namespace = dict(cls.__dict__,
|
||||||
@ -29,8 +29,8 @@ def protocol(cls: type) -> type:
|
|||||||
return type(name, bases, namespace)
|
return type(name, bases, namespace)
|
||||||
|
|
||||||
|
|
||||||
def is_protocol_class(cls):
|
def is_protocol_class(obj):
|
||||||
return inspect.isclass(cls) and cls.__dict__.get('_is_protocol', False)
|
return inspect.isclass(obj) and obj.__dict__.get('_is_protocol', False)
|
||||||
|
|
||||||
|
|
||||||
def is_public_function(obj):
|
def is_public_function(obj):
|
||||||
@ -53,7 +53,7 @@ class CallHandlerMeta(type):
|
|||||||
|
|
||||||
class CallHandler(metaclass=CallHandlerMeta):
|
class CallHandler(metaclass=CallHandlerMeta):
|
||||||
|
|
||||||
protocol_class: type
|
protocol_class: typing.Type
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
handle_call: typing.Optional[typing.Callable] = None):
|
handle_call: typing.Optional[typing.Callable] = None):
|
||||||
@ -70,16 +70,16 @@ class CallHandler(metaclass=CallHandlerMeta):
|
|||||||
|
|
||||||
|
|
||||||
def call_proxy_class(
|
def call_proxy_class(
|
||||||
cls: type,
|
cls: typing.Type,
|
||||||
*bases: type,
|
*bases: typing.Type,
|
||||||
class_name: typing.Optional[str] = None,
|
class_name: str = None,
|
||||||
namespace: typing.Optional[dict] = None) \
|
namespace: dict = None) \
|
||||||
-> type:
|
-> typing.Type:
|
||||||
if not inspect.isclass(cls):
|
if not inspect.isclass(cls):
|
||||||
raise TypeError(f"Object {cls} is not a class")
|
raise TypeError(f"Object {cls} is not a class")
|
||||||
if class_name is None:
|
if class_name is None:
|
||||||
class_name = cls.__name__ + 'Proxy'
|
class_name = cls.__name__ + 'Proxy'
|
||||||
protocol_classes = list_protocols(cls)
|
protocol_classes = list_protocols(typing.cast(typing.Hashable, cls))
|
||||||
if not protocol_classes:
|
if not protocol_classes:
|
||||||
raise TypeError(f"Class {cls} doesn't implement any protocol")
|
raise TypeError(f"Class {cls} doesn't implement any protocol")
|
||||||
if namespace is None:
|
if namespace is None:
|
||||||
@ -99,13 +99,13 @@ def call_proxy_class(
|
|||||||
return 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)
|
proxy_class = call_proxy_class(cls, CallHandler)
|
||||||
return proxy_class(handle_call)
|
return proxy_class(handle_call)
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache()
|
@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)
|
subclasses = inspect.getmro(cls)
|
||||||
protocols = tuple(cls
|
protocols = tuple(cls
|
||||||
for cls in subclasses
|
for cls in subclasses
|
||||||
|
@ -20,7 +20,7 @@ import shlex
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
ShellCommandType = typing.Union['ShellCommand', str, typing.Iterable[str]]
|
ShellCommandType = typing.Union['ShellCommand', str, typing.Iterable]
|
||||||
|
|
||||||
|
|
||||||
class ShellCommand(tuple):
|
class ShellCommand(tuple):
|
||||||
|
Loading…
Reference in New Issue
Block a user