protobuf: Annotate well_known_types.pyi (#9323)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Ilya Konstantinov
2022-12-05 13:49:55 -05:00
committed by GitHub
parent 503eab31d7
commit 578cebe1c5
4 changed files with 51 additions and 19 deletions

View File

@@ -36,3 +36,6 @@ google.protobuf.internal.containers.BaseContainer.__hash__
# Metaclass differs:
google.protobuf.descriptor.OneofDescriptor
# Runtime does not have __iter__ (yet...): hack in spirit of https://github.com/python/typeshed/issues/7813
google.protobuf.internal.well_known_types.ListValue.__iter__

View File

@@ -0,0 +1,18 @@
# pyright: reportUnnecessaryTypeIgnoreComment=true
from __future__ import annotations
from google.protobuf.struct_pb2 import ListValue, Struct
list_value = ListValue()
lst = list(list_value) # Ensure type checkers recognise that the class is iterable (doesn't have an `__iter__` method at runtime)
list_value[0] = 42.42
list_value[0] = "42"
list_value[0] = None
list_value[0] = True
list_value[0] = [42.42, "42", None, True, [42.42, "42", None, True], {"42": 42}]
list_value[0] = ListValue()
list_value[0] = Struct()
list_element = list_value[0]