-
Notifications
You must be signed in to change notification settings - Fork 83
Add googleapis as test fodder #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR integrates the googleapis repository as comprehensive test data for mypy-protobuf, significantly expanding test coverage from a few dozen to over 13,000 proto files. The changes address naming conflicts discovered during this integration where proto field names like property and collections clash with Python built-ins and standard library modules. The solution aliases all imported modules with underscore prefixes (e.g., import collections.abc as _collections_abc) and uses builtins.property for the @property decorator to avoid conflicts.
Key Changes:
- Modified import aliasing strategy to prefix all standard library imports with underscores
- Updated field name handling to use
builtins.propertyto avoid conflicts with@propertydecorator - Added googleapis as a third-party test target
- Extended test exclusions and cleanup procedures for the new test data
- Added test proto fields (
property,collections) to validate the fix
Reviewed changes
Copilot reviewed 77 out of 8800 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| run_test.sh | Adds googleapis proto generation, mypy validation, and cleanup steps to test pipeline |
| pyproject.toml | Excludes unittest proto stubs from type checking |
| proto/testproto/test.proto | Adds property and collections fields to test naming conflict resolution |
| proto/google/protobuf/*.proto | Adds Google protobuf test proto files for comprehensive testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0501cc0 to
a315eb8
Compare
a315eb8 to
615267b
Compare
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
git-subtree-dir: third_party/googleapis git-subtree-split: 347b0e45a6ec42e183e44ce11e0cb0eaf7f24caa
fe2d1b0 to
cf7009f
Compare
I think I'm going to try changing up the imports to be |
|
And I think there's a latent bug in this implementation where import names would conflict.
|
81b33c6 to
c0824e3
Compare
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
b0fbcdc to
7706bb1
Compare
This is done. It fixed a ton of possible corner cases, and passes all tests. Lots of field names would have caused issues that won't anymore. |
7706bb1 to
0d8e9ab
Compare
|
protoc generator: this pr: |
0d8e9ab to
fc318b5
Compare
- Move to model similar to protoc pyi generator. This prevents name collisions in field names
- `from test.a.b import c as _c`
- If multiple names collied, append `_{count}`
- `from test.a.x import c as _c_1`
- Fix bug in duplicate package name imports
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
fc318b5 to
65f6350
Compare
* Re-use import aliasing logic for readable stubs and re-exporting. * Fixes issues with readable stubs and grpc sync/async Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
f55187c to
5564d61
Compare
|
@nipunn1313 I think I'm pretty happy with this and ready for review. It aligns more closely with the built in pyi generator, and fixes a ton of possible corner cases with field naming. It adds 6500+ files for testing, and a few more corner case tests I found. It's another breaking change, but it fixes readable stubs with grpc, allows for more deprecation, and hopefully I can take a break after this one :D |
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
|
I just added envoy protos as well, which depended on otel, googleapis, and prometheus as well. Envoy also depends on googleapis protos, so its a bit redundant, but the test time is pretty low, so it didn't feel necessary to remove googleapis. |
|
I can't really review this - there's too many changes. I feel like pulling in 6500+ files copied in for testing may make the repo get out of hand? I feel like doing this exercise is useful to help find bugs, but I'm not really convinced it's helpful for regression testing. Instead as an idea, we could do this exercise to uncover bugs, and then write tests that are specific to the bugs being fixed. I think it'll make the repo more maintainable in this way. Maybe we could have instructions on how to do this manual process of testing? |
Yeah I realized this and pulled the subtree commits. Now it just pulls it in during a test run and cleans up after. I can squash this history so that the changes aren't in the commits, and that will be easier to review. I felt that just pulling in the Google protobuf tree was small enough, but I can make that a 3rd party test as well. |
Pulling in the whole googleapis tree, generating stubs, and running mypy on them.
Found a few things.
Fields named
propertyandcollectionscaused conflicts with@propertyandcollections.abc.Iterable. In theory this means that fields calledbuiltins,typing, or other built in names could cause issues.To work around this I did 2 things.
property->builtins.property, and all the import names aliased.This is similar to how the first party
.pyigenerator does it (from collections.abc import Mapping as _Mapping), but matching that exactly would have required more architectural changes.During this switch, I found out that
flake8does ast parsing on string names, so_typingdoes not get parsed astyping, this caused a few issues, but I added somenoqa's to handle those. I figure most people aren't running flake8 on their generated stubs.Overall the change seems large, but conceptually it's a very minor change. And we're now testing on over 6500 proto files!!!
It also turns out that even though
mypy-protobufreserves field numbers 1151-1154, google itself appears to not respect it. 😬