Fix most mypy warnings

This commit is contained in:
Nat Noordanus 2020-06-07 19:10:41 +02:00
parent 3185c67098
commit c8229e53a7
4 changed files with 15 additions and 10 deletions

View File

@ -440,7 +440,7 @@ class ProtoClassMetadata:
def __init__(self, cls: Type["Message"]):
by_field = {}
by_group = {}
by_group: Dict[str, Set] = {}
by_field_name = {}
by_field_number = {}
@ -780,7 +780,7 @@ class Message(ABC):
def to_dict(
self, casing: Casing = Casing.CAMEL, include_default_values: bool = False
) -> dict:
) -> Dict[str, Any]:
"""
Returns a dict representation of this message instance which can be
used to serialize to e.g. JSON. Defaults to camel casing for

View File

@ -1,4 +1,8 @@
from typing import TypeVar
from typing import TYPE_CHECKING, TypeVar
if TYPE_CHECKING:
from . import Message
from grpclib._protocols import IProtoMessage
# Bound type variable to allow methods to return `self` of subclasses
T = TypeVar("T", bound="Message")

View File

@ -3,9 +3,10 @@ import asyncio
import grpclib.const
from typing import (
Any,
AsyncIterable,
AsyncIterator,
Collection,
Iterator,
Iterable,
Mapping,
Optional,
Tuple,
@ -23,7 +24,7 @@ if TYPE_CHECKING:
_Value = Union[str, bytes]
_MetadataLike = Union[Mapping[str, _Value], Collection[Tuple[str, _Value]]]
_MessageSource = Union[Iterator["IProtoMessage"], AsyncIterator["IProtoMessage"]]
_MessageSource = Union[Iterable["IProtoMessage"], AsyncIterable["IProtoMessage"]]
class ServiceStub(ABC):
@ -160,7 +161,7 @@ class ServiceStub(ABC):
@staticmethod
async def _send_messages(stream, messages: _MessageSource):
if hasattr(messages, "__aiter__"):
if isinstance(messages, AsyncIterable):
async for message in messages:
await stream.send_message(message)
else:

View File

@ -6,10 +6,10 @@ import re
import stringcase
import sys
import textwrap
from typing import List
from typing import List, Union
import betterproto
from betterproto.casing import safe_snake_case
from betterproto.compile.importing import get_ref_type
import betterproto
try:
# betterproto[compiler] specific dependencies
@ -58,8 +58,8 @@ def py_type(
raise NotImplementedError(f"Unknown type {descriptor.type}")
def get_py_zero(type_num: int) -> str:
zero = 0
def get_py_zero(type_num: int) -> Union[str, float]:
zero: Union[str, float] = 0
if type_num in []:
zero = 0.0
elif type_num == 8: