Skip to content

Commit

Permalink
Fix most mypy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Jun 14, 2020
1 parent 1161d08 commit 9a323bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -780,7 +780,7 @@ def FromString(cls: Type[T], data: bytes) -> T:

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
Expand Down
6 changes: 5 additions & 1 deletion betterproto/_types.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
7 changes: 4 additions & 3 deletions betterproto/grpc/grpclib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import grpclib.const
from typing import (
Any,
AsyncIterable,
AsyncIterator,
Collection,
Iterator,
Iterable,
Mapping,
Optional,
Tuple,
Expand All @@ -23,7 +24,7 @@

_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):
Expand Down Expand Up @@ -160,7 +161,7 @@ async def _stream_stream(

@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:
Expand Down
8 changes: 4 additions & 4 deletions betterproto/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9a323bc

Please sign in to comment.