Skip to content

Commit

Permalink
Satiate mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
software-dov committed Oct 8, 2020
1 parent e1e8f68 commit f88fc4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def build(
opts: Options = Options(),
prior_protos: Mapping[str, 'Proto'] = None,
load_services: bool = True,
all_resources: Optional[Mapping[str, wrappers.CommonResource]] = None,
all_resources: Optional[Mapping[str, wrappers.MessageType]] = None,
) -> 'Proto':
"""Build and return a Proto instance.
Expand Down Expand Up @@ -424,7 +424,7 @@ def __init__(
opts: Options = Options(),
prior_protos: Mapping[str, Proto] = None,
load_services: bool = True,
all_resources: Optional[Mapping[str, wrappers.CommonResource]] = None,
all_resources: Optional[Mapping[str, wrappers.MessageType]] = None,
):
self.proto_messages: Dict[str, wrappers.MessageType] = {}
self.proto_enums: Dict[str, wrappers.EnumType] = {}
Expand Down Expand Up @@ -466,9 +466,11 @@ def __init__(
# below is because `repeated DescriptorProto message_type = 4;` in
# descriptor.proto itself).
self._load_children(file_descriptor.enum_type, self._load_enum,
address=self.address, path=(5,), resources=all_resources)
address=self.address, path=(5,),
resources=all_resources or {})
self._load_children(file_descriptor.message_type, self._load_message,
address=self.address, path=(4,), resources=all_resources)
address=self.address, path=(4,),
resources=all_resources or {})

# Edge case: Protocol buffers is not particularly picky about
# ordering, and it is possible that a message will have had a field
Expand Down Expand Up @@ -503,7 +505,8 @@ def __init__(
# same files.
if file_to_generate and load_services:
self._load_children(file_descriptor.service, self._load_service,
address=self.address, path=(6,), resources=all_resources)
address=self.address, path=(6,),
resources=all_resources or {})
# TODO(lukesneeringer): oneofs are on path 7.

@property
Expand Down Expand Up @@ -563,7 +566,7 @@ def api_messages(self) -> Mapping[str, wrappers.MessageType]:
def _load_children(self,
children: Sequence, loader: Callable, *,
address: metadata.Address, path: Tuple[int, ...],
resources: Mapping[str, wrappers.CommonResource]) -> Mapping:
resources: Mapping[str, wrappers.MessageType]) -> Mapping:
"""Return wrapped versions of arbitrary children from a Descriptor.
Args:
Expand Down Expand Up @@ -830,7 +833,7 @@ def _load_message(self,
message_pb: descriptor_pb2.DescriptorProto,
address: metadata.Address,
path: Tuple[int],
resources: Mapping[str, wrappers.CommonResource],
resources: Mapping[str, wrappers.MessageType],
) -> wrappers.MessageType:
"""Load message descriptions from DescriptorProtos."""
address = address.child(message_pb.name, path)
Expand Down Expand Up @@ -895,7 +898,7 @@ def _load_enum(self,
enum: descriptor_pb2.EnumDescriptorProto,
address: metadata.Address,
path: Tuple[int],
resources: Mapping[str, wrappers.CommonResource],
resources: Mapping[str, wrappers.MessageType],
) -> wrappers.EnumType:
"""Load enum descriptions from EnumDescriptorProtos."""
address = address.child(enum.name, path)
Expand Down Expand Up @@ -926,7 +929,7 @@ def _load_service(self,
service: descriptor_pb2.ServiceDescriptorProto,
address: metadata.Address,
path: Tuple[int],
resources: Mapping[str, wrappers.CommonResource],
resources: Mapping[str, wrappers.MessageType],
) -> wrappers.Service:
"""Load comments for a service and its methods."""
address = address.child(service.name, path)
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def recursive_field_types(self) -> Sequence[
return tuple(types)

@utils.cached_property
def recursive_fields(self) -> Sequence[Field]:
def recursive_fields(self) -> FrozenSet[Field]:
return frozenset(chain(
self.fields.values(),
(field
Expand Down

0 comments on commit f88fc4c

Please sign in to comment.