Skip to content

Conversation

@aidandj
Copy link
Collaborator

@aidandj aidandj commented Dec 10, 2025

This generates properties instead of attributes for methods, enum values, message fields and adds deprecation decoration if the option is set.

Copy link

Copilot AI left a 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 enhances deprecation support in the mypy-protobuf plugin by generating properties instead of attributes for deprecated protobuf elements, allowing proper deprecation warnings to be surfaced through type checking.

Key changes:

  • Deprecated message fields, gRPC methods, and enum values are now generated as properties with @deprecated decorators
  • This enables mypy to catch usage of deprecated elements at type-check time
  • Test expectations updated to reflect 9 additional deprecation warnings (from 105 to 114 errors)

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test_negative/output.expected.* Updated expected mypy error counts and line numbers to reflect new deprecation warnings
test_negative/negative.py Added test cases for deprecated fields, methods, and enum values
test/test_generated_mypy.py Updated error count assertion from 90 to 96
test/generated_concrete/testproto/test_pb2.pyi Generated deprecated message fields as properties with deprecation decorators
test/generated_concrete/testproto/grpc/dummy_pb2_grpc.pyi Generated deprecated gRPC methods as properties with deprecation decorators
test/generated_concrete/testproto/grpc/dummy_pb2.pyi Generated deprecated request fields as properties with deprecation decorators
stubtest_allowlist.txt Updated allowlist for properties that don't exist at runtime
run_test.sh Added logging for stubtest execution
proto/testproto/test.proto Added deprecated field definitions for testing
proto/testproto/grpc/dummy.proto Added deprecated method definitions for testing
CHANGELOG.md Documented the new deprecation property generation feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aidandj aidandj force-pushed the aidan/more-deprecation-support branch from 98e7152 to 4d7046f Compare December 15, 2025 04:17
Copy link
Owner

@nipunn1313 nipunn1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice feature!

Copy link
Owner

@nipunn1313 nipunn1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose - this is the kind of feature that might break on some corner case that we didn't anticipate. If there are any large .proto codebases out in the wild we could try it on, that could help give some confidence

@aidandj
Copy link
Collaborator Author

aidandj commented Dec 17, 2025

I suppose - this is the kind of feature that might break on some corner case that we didn't anticipate. If there are any large .proto codebases out in the wild we could try it on, that could help give some confidence

I asked for some input in issues and haven't heard, I'll do some more looking tonight. I added all the Google protobuf protos as a test, but they don't use my deprecation.

At first I changed them all to properties, but to minimize the blast radius I did it only for deprecated objects.

I know of a few large protobuf projects, but finding one that uses mypy protobuf, is fully static typed has been more challenging.

git-subtree-dir: third_party/googleapis
git-subtree-split: 6d6acd2e993c45a7a45fc6374d6c2fc987af1f77
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
Signed-off-by: Aidan Jensen <aidandj.github@gmail.com>
* Express methods as properties, allows for deprecation
* Express enum values as properties, allows for deprecation

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>
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>
@aidandj aidandj force-pushed the aidan/more-deprecation-support branch from 4d7046f to 4b0decf Compare December 18, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants