Skip to content

Commit c8229e5

Browse files
committed
Fix most mypy warnings
1 parent 3185c67 commit c8229e5

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

betterproto/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class ProtoClassMetadata:
440440

441441
def __init__(self, cls: Type["Message"]):
442442
by_field = {}
443-
by_group = {}
443+
by_group: Dict[str, Set] = {}
444444
by_field_name = {}
445445
by_field_number = {}
446446

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

781781
def to_dict(
782782
self, casing: Casing = Casing.CAMEL, include_default_values: bool = False
783-
) -> dict:
783+
) -> Dict[str, Any]:
784784
"""
785785
Returns a dict representation of this message instance which can be
786786
used to serialize to e.g. JSON. Defaults to camel casing for

betterproto/_types.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from typing import TypeVar
1+
from typing import TYPE_CHECKING, TypeVar
2+
3+
if TYPE_CHECKING:
4+
from . import Message
5+
from grpclib._protocols import IProtoMessage
26

37
# Bound type variable to allow methods to return `self` of subclasses
48
T = TypeVar("T", bound="Message")

betterproto/grpc/grpclib_client.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import grpclib.const
44
from typing import (
55
Any,
6+
AsyncIterable,
67
AsyncIterator,
78
Collection,
8-
Iterator,
9+
Iterable,
910
Mapping,
1011
Optional,
1112
Tuple,
@@ -23,7 +24,7 @@
2324

2425
_Value = Union[str, bytes]
2526
_MetadataLike = Union[Mapping[str, _Value], Collection[Tuple[str, _Value]]]
26-
_MessageSource = Union[Iterator["IProtoMessage"], AsyncIterator["IProtoMessage"]]
27+
_MessageSource = Union[Iterable["IProtoMessage"], AsyncIterable["IProtoMessage"]]
2728

2829

2930
class ServiceStub(ABC):
@@ -160,7 +161,7 @@ async def _stream_stream(
160161

161162
@staticmethod
162163
async def _send_messages(stream, messages: _MessageSource):
163-
if hasattr(messages, "__aiter__"):
164+
if isinstance(messages, AsyncIterable):
164165
async for message in messages:
165166
await stream.send_message(message)
166167
else:

betterproto/plugin.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import stringcase
77
import sys
88
import textwrap
9-
from typing import List
9+
from typing import List, Union
10+
import betterproto
1011
from betterproto.casing import safe_snake_case
1112
from betterproto.compile.importing import get_ref_type
12-
import betterproto
1313

1414
try:
1515
# betterproto[compiler] specific dependencies
@@ -58,8 +58,8 @@ def py_type(
5858
raise NotImplementedError(f"Unknown type {descriptor.type}")
5959

6060

61-
def get_py_zero(type_num: int) -> str:
62-
zero = 0
61+
def get_py_zero(type_num: int) -> Union[str, float]:
62+
zero: Union[str, float] = 0
6363
if type_num in []:
6464
zero = 0.0
6565
elif type_num == 8:

0 commit comments

Comments
 (0)