Uh oh!
There was an error while loading. Please reload this page.
Add/fix types to a bunch of non-generated protobuf files - #7017
Conversation
5a46e44 to
ce42fd7CompareAlexWaygood
commented
Jan 24, 2022
I've just filed #7019 for some of the unrelated CI errors. |
JelleZijlstra
commented
Jan 24, 2022
A number of other CI failures are real though. |
bc540f9 to
02a81c7Comparenipunn1313
commented
Jan 24, 2022
Looks better now! Thanks for prompt fix on the other things. |
Uh oh!
There was an error while loading. Please reload this page.
srittau
left a comment
There was a problem hiding this comment.
Two nits below and one question, but LGTM otherwise, although my protobuf knowledge is limited.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Sebastian Rittau <srittau@rittau.biz>
| _T = TypeVar("_T") | ||
| class _ValueChecker(Protocol[_T]): |
There was a problem hiding this comment.
I put an underscore here since the protocol is not an actual element exposed within this module.
| class TypeCheckerWithDefault(TypeChecker[_T]): | ||
| def __init__(self, default_value: _T, *acceptable_types: _T): ... | ||
| def DefaultValue(self) -> _T: ... |
There was a problem hiding this comment.
Ideally we could assert that TypeCheckerWithDefault[_T] implements the protocol here.
I know there was some discussion on typing-sig to have this be supported in typecheckers
For now I checked manually.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
neruson
commented
Feb 3, 2022
Hi @nipunn1313 and others, thank you for your excellent work! I had a question about this PR because my CI builds started failing with the upgrade from types-protobuf 3.19.7 to 3.19.8. Specifically, this line is causing issues, because my code is assuming that DESCRIPTOR will not be None. https://github.com/nipunn1313/typeshed/blob/45a2256f397f9810944e8fccff53dc36471cb3ce/stubs/protobuf/google/protobuf/message.pyi#L14 I do see that the Message abstract base class has I don't think None is actually a valid option for |
nipunn1313
commented
Feb 3, 2022
Yep that makes sense to me @neruson. Make a PR + Add a comment explaining the non-nullable bit and I'll take a look! In practicality, you're never actually instantiating the base class. |
| def FromString(cls: type[Self], s: bytes) -> Self: ... | ||
| # The TypeVar must be bound to `Message` or we get mypy errors, so we cannot use `Self` for `Extensions` | ||
| @property | ||
| def Extensions(self: _M) -> _ExtensionDict[_M]: ... |
There was a problem hiding this comment.
Hi all, my CI starts failing because of some my code trying to get the extensions:
extensions=field_descriptor.GetOptions().ExtensionsWhere did that go? Is it invalid to get the Extensions that way?
There was a problem hiding this comment.
cool. I can repro this with the mypy-protobuf tests, but not with these tests.
I think stubtest got confused because the Message base class doesn't obviously have Extensions field (per this comment)
https://github.com/protocolbuffers/protobuf/blob/master/python/google/protobuf/message.py#L67
Here's a repro
nipunn1313/mypy-protobuf#346
https://github.com/nipunn1313/mypy-protobuf/runs/5095806933?check_suite_focus=true
I think we can bring this back.
I'd also like to look into running mypy-protobuf's testsuite from PR's to typeshed. I'll also look into that.
Used stubtest warnings as guidance as well as the source
https://github.com/protocolbuffers/protobuf/tree/master/python/google/protobuf