├── test ├── __init__.py ├── generated │ ├── testproto │ │ ├── __init__.py │ │ ├── dot │ │ │ ├── __init__.py │ │ │ └── com │ │ │ │ ├── __init__.py │ │ │ │ └── test_pb2.pyi │ │ ├── grpc │ │ │ ├── __init__.py │ │ │ ├── import_pb2.pyi │ │ │ └── import_pb2_grpc.pyi │ │ ├── inner │ │ │ ├── __init__.py │ │ │ └── inner_pb2.pyi │ │ ├── nested │ │ │ ├── __init__.py │ │ │ └── nested_pb2.pyi │ │ ├── Capitalized │ │ │ ├── __init__.py │ │ │ └── Capitalized_pb2.pyi │ │ ├── reexport_pb2.pyi │ │ ├── readme_enum_pb2.pyi │ │ ├── test_no_generic_services_pb2.pyi │ │ ├── test_extensions2_pb2.pyi │ │ ├── nopackage_pb2.pyi │ │ ├── test_extensions3_pb2.pyi │ │ ├── comment_special_chars_pb2.pyi │ │ ├── edition2024_pb2.pyi │ │ └── test3_pb2.pyi │ ├── mypy_protobuf │ │ ├── __init__.py │ │ └── extensions_pb2.pyi │ └── google │ │ └── protobuf │ │ └── duration_pb2.pyi ├── generated_async_only │ └── testproto │ │ ├── __init__.py │ │ ├── dot │ │ ├── __init__.py │ │ └── com │ │ │ ├── __init__.py │ │ │ ├── test_pb2_grpc.pyi │ │ │ └── test_pb2.pyi │ │ ├── grpc │ │ ├── __init__.py │ │ ├── import_pb2.pyi │ │ └── import_pb2_grpc.pyi │ │ ├── inner │ │ ├── __init__.py │ │ ├── inner_pb2_grpc.pyi │ │ └── inner_pb2.pyi │ │ ├── nested │ │ ├── __init__.py │ │ ├── nested_pb2_grpc.pyi │ │ └── nested_pb2.pyi │ │ ├── Capitalized │ │ ├── __init__.py │ │ ├── Capitalized_pb2_grpc.pyi │ │ └── Capitalized_pb2.pyi │ │ ├── nopackage_pb2_grpc.pyi │ │ ├── readme_enum_pb2_grpc.pyi │ │ ├── test3_pb2_grpc.pyi │ │ ├── test_extensions2_pb2_grpc.pyi │ │ ├── test_extensions3_pb2_grpc.pyi │ │ ├── comment_special_chars_pb2_grpc.pyi │ │ ├── edition2024_pb2_grpc.pyi │ │ ├── reexport_pb2_grpc.pyi │ │ ├── reexport_pb2.pyi │ │ ├── readme_enum_pb2.pyi │ │ ├── test_no_generic_services_pb2_grpc.pyi │ │ ├── test_no_generic_services_pb2.pyi │ │ ├── test_extensions2_pb2.pyi │ │ ├── test_pb2_grpc.pyi │ │ ├── nopackage_pb2.pyi │ │ ├── test_extensions3_pb2.pyi │ │ ├── comment_special_chars_pb2.pyi │ │ ├── edition2024_pb2.pyi │ │ └── test3_pb2.pyi ├── generated_sync_only │ └── testproto │ │ ├── __init__.py │ │ ├── dot │ │ ├── __init__.py │ │ └── com │ │ │ ├── __init__.py │ │ │ ├── test_pb2_grpc.pyi │ │ │ └── test_pb2.pyi │ │ ├── grpc │ │ ├── __init__.py │ │ ├── import_pb2.pyi │ │ └── import_pb2_grpc.pyi │ │ ├── inner │ │ ├── __init__.py │ │ ├── inner_pb2_grpc.pyi │ │ └── inner_pb2.pyi │ │ ├── nested │ │ ├── __init__.py │ │ ├── nested_pb2_grpc.pyi │ │ └── nested_pb2.pyi │ │ ├── Capitalized │ │ ├── __init__.py │ │ ├── Capitalized_pb2_grpc.pyi │ │ └── Capitalized_pb2.pyi │ │ ├── nopackage_pb2_grpc.pyi │ │ ├── readme_enum_pb2_grpc.pyi │ │ ├── test_extensions2_pb2_grpc.pyi │ │ ├── test_extensions3_pb2_grpc.pyi │ │ ├── comment_special_chars_pb2_grpc.pyi │ │ ├── test3_pb2_grpc.pyi │ │ ├── edition2024_pb2_grpc.pyi │ │ ├── reexport_pb2_grpc.pyi │ │ ├── reexport_pb2.pyi │ │ ├── test_no_generic_services_pb2_grpc.pyi │ │ ├── readme_enum_pb2.pyi │ │ ├── test_no_generic_services_pb2.pyi │ │ ├── test_extensions2_pb2.pyi │ │ ├── test_pb2_grpc.pyi │ │ ├── nopackage_pb2.pyi │ │ ├── test_extensions3_pb2.pyi │ │ ├── comment_special_chars_pb2.pyi │ │ └── edition2024_pb2.pyi ├── test_concrete.py ├── generated_concrete │ ├── testproto │ │ ├── grpc │ │ │ ├── import_pb2.pyi │ │ │ └── import_pb2_grpc.pyi │ │ ├── reexport_pb2.pyi │ │ ├── dot │ │ │ └── com │ │ │ │ └── test_pb2.pyi │ │ ├── inner │ │ │ └── inner_pb2.pyi │ │ ├── readme_enum_pb2.pyi │ │ ├── test_no_generic_services_pb2.pyi │ │ ├── test_extensions2_pb2.pyi │ │ ├── nopackage_pb2.pyi │ │ ├── Capitalized │ │ │ └── Capitalized_pb2.pyi │ │ ├── test_extensions3_pb2.pyi │ │ ├── comment_special_chars_pb2.pyi │ │ ├── edition2024_pb2.pyi │ │ └── nested │ │ │ └── nested_pb2.pyi │ ├── mypy_protobuf │ │ └── extensions_pb2.pyi │ └── google │ │ └── protobuf │ │ └── duration_pb2.pyi ├── test_grpc_async_usage.py ├── test_grpc_usage.py ├── sync_only │ └── test_sync_only.py └── async_only │ └── test_async_only.py ├── mypy_protobuf ├── __init__.py ├── protoc_gen_mypy.bat ├── extensions_pb2.py └── extensions_pb2.pyi ├── test_negative └── __init__.py ├── uv.lock ├── mypy_requirements.txt ├── .gitattributes ├── proto ├── testproto │ ├── dot.com │ │ └── test.proto │ ├── readme_enum.proto │ ├── inner │ │ └── inner.proto │ ├── test_no_generic_services.proto │ ├── nopackage.proto │ ├── reexport.proto │ ├── Capitalized │ │ └── Capitalized.proto │ ├── test_extensions2.proto │ ├── grpc │ │ └── import.proto │ ├── nested │ │ └── nested.proto │ ├── edition2024.proto │ ├── comment_special_chars.proto │ ├── test_extensions3.proto │ ├── test3.proto │ └── test.proto ├── mypy_protobuf │ └── extensions.proto └── google │ └── protobuf │ └── duration.proto ├── .github ├── package.json ├── dependabot.yml └── workflows │ └── main.yml ├── test_requirements.txt ├── .flake8 ├── .gitignore ├── setup.cfg └── pyproject.toml /test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mypy_protobuf/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test_negative/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/mypy_protobuf/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/dot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/grpc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/inner/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/nested/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/Capitalized/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated/testproto/dot/com/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/dot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/grpc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/inner/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/dot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/grpc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/inner/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/nested/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/dot/com/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/nested/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/Capitalized/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/dot/com/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/Capitalized/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /uv.lock: -------------------------------------------------------------------------------- 1 | version = 1 2 | revision = 3 3 | requires-python = ">=3.14" 4 | -------------------------------------------------------------------------------- /mypy_protobuf/protoc_gen_mypy.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %~dp0\python -u %0\..\protoc-gen-mypy 3 | -------------------------------------------------------------------------------- /mypy_requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements to run mypy itself. Mypy executable exists in a separate venv. 2 | mypy==1.19.0 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | test_negative/output.expected.2.7 linguist-generated=true 2 | test_negative/output.expected.3.8 linguist-generated=true 3 | -------------------------------------------------------------------------------- /proto/testproto/dot.com/test.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package test; 3 | 4 | message TestMessage { 5 | string foo = 1; 6 | } 7 | -------------------------------------------------------------------------------- /proto/testproto/readme_enum.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test; 4 | 5 | enum MyEnum { 6 | HELLO = 0; 7 | WORLD = 1; 8 | } 9 | -------------------------------------------------------------------------------- /.github/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fake_package_json_for_github_action_to_read_version", 3 | "private": true, 4 | "devDependencies": { 5 | "pyright": "1.1.407" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /proto/testproto/inner/inner.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package inner; 4 | 5 | import "testproto/test3.proto"; 6 | 7 | message Inner { 8 | test3.OuterEnum a = 1; 9 | } 10 | -------------------------------------------------------------------------------- /test/test_concrete.py: -------------------------------------------------------------------------------- 1 | from testproto.grpc.dummy_pb2_grpc import DummyServiceServicer 2 | 3 | 4 | class IncompleteServicer(DummyServiceServicer): 5 | pass 6 | 7 | 8 | incomplete = IncompleteServicer() 9 | -------------------------------------------------------------------------------- /test/generated/testproto/grpc/import_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | 8 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 9 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/grpc/import_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | 8 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 9 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/grpc/import_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | 8 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 9 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/grpc/import_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | 8 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 9 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/nopackage_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/inner/inner_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/nopackage_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/readme_enum_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /proto/testproto/test_no_generic_services.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package test; 4 | 5 | message Simple3 { 6 | required string a_string = 1; 7 | } 8 | 9 | service ATestService2 { 10 | rpc Echo(Simple3) returns (Simple3) {} 11 | } 12 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/dot/com/test_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/inner/inner_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/nested/nested_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/readme_enum_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/dot/com/test_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/nested/nested_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_extensions2_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_extensions3_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test_requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements to run unit tests. Tests import from 2 | # generated code. 3 | protobuf==6.32.1 4 | pytest==8.4.2 5 | types-grpcio==1.0.0.20251009 6 | pytest-asyncio==0.25.3 7 | grpcio-tools==1.76.0 8 | types-protobuf==6.32.1.20251105 9 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test3_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | package test3""" 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_extensions2_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_extensions3_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/comment_special_chars_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test3_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | package test3""" 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /proto/testproto/nopackage.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | // Intentionally don't set a package - just to make sure we can handle it. 4 | 5 | message NoPackage {} 6 | message NoPackage2 { 7 | NoPackage np = 1; 8 | repeated NoPackage np_rep = 2; 9 | } 10 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/Capitalized/Capitalized_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/comment_special_chars_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/Capitalized/Capitalized_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /proto/testproto/reexport.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test3; 4 | 5 | // Should be reexported 6 | import public "testproto/test3.proto"; 7 | import public "google/protobuf/empty.proto"; 8 | // Not reexported 9 | import "testproto/inner/inner.proto"; 10 | -------------------------------------------------------------------------------- /proto/testproto/Capitalized/Capitalized.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package Capitalized; 4 | 5 | message lower { 6 | int64 a = 1; 7 | } 8 | 9 | message Upper { 10 | lower Lower = 1; 11 | } 12 | 13 | message lower2 { 14 | Upper upper = 1; 15 | } 16 | -------------------------------------------------------------------------------- /proto/testproto/test_extensions2.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "testproto/test.proto"; 4 | 5 | package test; 6 | 7 | message SeparateFileExtension { 8 | extend Simple2 { optional SeparateFileExtension ext = 1001; } 9 | 10 | optional bool flag = 1; 11 | } -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/edition2024_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/edition2024_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import collections.abc 7 | 8 | 9 | GRPC_GENERATED_VERSION: str 10 | GRPC_VERSION: str 11 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | per-file-ignores = 3 | *.py: E203, E301, E302, E305, E501 4 | *.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y037 5 | *_pb2.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y037, Y021, Y053 6 | *_pb2_grpc.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822, Y037, Y021, Y023, Y053 7 | 8 | extend_exclude = venv*,*_pb2.py,*_pb2_grpc.py,build/ 9 | -------------------------------------------------------------------------------- /proto/testproto/grpc/import.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "testproto/test.proto"; 4 | import "google/protobuf/empty.proto"; 5 | 6 | package test.grpc; 7 | 8 | // SimpleService 9 | service SimpleService { 10 | // UnaryUnary 11 | rpc UnaryUnary (google.protobuf.Empty) returns (test.Simple1) {} 12 | // UnaryStream 13 | rpc UnaryStream (test.Simple1) returns (google.protobuf.Empty) {} 14 | rpc NoComment (test.Simple1) returns (google.protobuf.Empty) {} 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /main 2 | .*.swp 3 | __pycache__/ 4 | .cache 5 | .mypy_cache/ 6 | /env/ 7 | /mypy_env/ 8 | *.pyc 9 | /test/generated/**/*.py 10 | !/test/generated/**/__init__.py 11 | /test/generated_concrete/**/*.py 12 | !/test/generated_concrete/**/__init__.py 13 | /test/generated_async_only/**/*.py 14 | !/test/generated_async_only/**/__init__.py 15 | /test/generated_sync_only/**/*.py 16 | !/test/generated_sync_only/**/__init__.py 17 | .pytest_cache 18 | /build/ 19 | /dist/ 20 | *.egg-info 21 | .idea/ 22 | .DS_Store 23 | /venv_* 24 | /protoc_* 25 | -------------------------------------------------------------------------------- /test/generated/testproto/reexport_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/reexport_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | 20 | GRPC_GENERATED_VERSION: str 21 | GRPC_VERSION: str 22 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/reexport_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/reexport_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import collections.abc 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | 20 | GRPC_GENERATED_VERSION: str 21 | GRPC_VERSION: str 22 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/reexport_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/reexport_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import google.protobuf.descriptor 7 | from google.protobuf.empty_pb2 import ( 8 | Empty as Empty, 9 | ) 10 | from testproto.test3_pb2 import ( 11 | BAR3 as BAR3, 12 | FOO3 as FOO3, 13 | OuterEnum as OuterEnum, 14 | OuterMessage3 as OuterMessage3, 15 | SimpleProto3 as SimpleProto3, 16 | UNKNOWN as UNKNOWN, 17 | ) 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | -------------------------------------------------------------------------------- /proto/testproto/nested/nested.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package test.nested_package; 4 | 5 | import "testproto/test3.proto"; 6 | 7 | message Nested { 8 | test3.OuterEnum a = 1; 9 | } 10 | 11 | message AnotherNested { 12 | enum NestedEnum { 13 | INVALID = 0; 14 | ONE = 1; 15 | TWO = 2; 16 | } 17 | 18 | message NestedMessage { 19 | enum NestedEnum2 { 20 | UNDEFINED = 0; 21 | NESTED_ENUM1 = 1; 22 | NESTED_ENUM2 = 2; 23 | } 24 | string s = 1; 25 | bool b = 2; 26 | NestedEnum ne = 3; 27 | NestedEnum2 ne2 = 4; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "pip" 9 | directory: "/" 10 | schedule: 11 | interval: "daily" 12 | - package-ecosystem: "npm" 13 | directory: ".github" 14 | schedule: 15 | interval: "daily" 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | schedule: 19 | interval: "daily" 20 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = mypy-protobuf 3 | version = attr: mypy_protobuf.main.__version__ 4 | description = Generate mypy stub files from protobuf specs 5 | keywords = mypy proto dropbox 6 | license = Apache License 2.0 7 | author = Nipunn Koorapati 8 | author_email = nipunn1313@gmail.com 9 | url = https://github.com/nipunn1313/mypy-protobuf 10 | download_url = https://github.com/nipunn1313/mypy-protobuf/releases 11 | 12 | [options] 13 | py_modules = 14 | mypy_protobuf 15 | mypy_protobuf.main 16 | mypy_protobuf.extensions_pb2 17 | install_requires = 18 | protobuf>=4.25.3 19 | types-protobuf>=4.24 20 | python_requires = >=3.8 21 | 22 | [options.entry_points] 23 | console_scripts = 24 | protoc-gen-mypy = mypy_protobuf.main:main 25 | protoc-gen-mypy_grpc = mypy_protobuf.main:grpc 26 | -------------------------------------------------------------------------------- /proto/mypy_protobuf/extensions.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package mypy_protobuf; 4 | 5 | import "google/protobuf/descriptor.proto"; 6 | 7 | message FieldOptions { 8 | // Tells mypy-protobuf to use a specific newtype rather than the normal type for this field. 9 | string casttype = 1; 10 | // Tells mypy-protobuf to use a specific type for keys; only makes sense on map fields 11 | string keytype = 2; 12 | // Tells mypy-protobuf to use a specific type for values; only makes sense on map fields 13 | string valuetype = 3; 14 | 15 | } 16 | 17 | extend google.protobuf.FieldOptions { 18 | // Custom field options from mypy-protobuf 19 | FieldOptions options = 1154; 20 | 21 | // Legacy fields. Prefer to use ones within `options` instead. 22 | string casttype = 1151 [deprecated = true]; 23 | string keytype = 1152 [deprecated = true]; 24 | string valuetype = 1153 [deprecated = true]; 25 | } 26 | -------------------------------------------------------------------------------- /proto/testproto/edition2024.proto: -------------------------------------------------------------------------------- 1 | // Edition version of proto2 file 2 | edition = "2024"; 3 | 4 | package test; 5 | 6 | option features.utf8_validation = NONE; 7 | option features.enforce_naming_style = STYLE_LEGACY; 8 | option features.default_symbol_visibility = EXPORT_ALL; 9 | 10 | message Editions2024SubMessage { 11 | string thing = 1; 12 | } 13 | 14 | message Editions2024Test { 15 | // Expect to be always set 16 | string legacy = 1 [features.field_presence = LEGACY_REQUIRED]; 17 | // Expect HasField generated 18 | string explicit_singular = 2 [features.field_presence = EXPLICIT]; 19 | // Expect HasField generated? 20 | Editions2024SubMessage message_field = 3 [features.field_presence = EXPLICIT]; 21 | // Expect implicit field presence, no HasField generated 22 | string implicit_singular = 4 [features.field_presence = IMPLICIT]; 23 | // Not set, should default to EXPLICIT 24 | string default_singular = 5; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_no_generic_services_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import grpc 9 | import testproto.test_no_generic_services_pb2 10 | import typing 11 | 12 | 13 | GRPC_GENERATED_VERSION: str 14 | GRPC_VERSION: str 15 | 16 | class ATestService2Stub: 17 | def __init__(self, channel: grpc.Channel) -> None: ... 18 | Echo: grpc.UnaryUnaryMultiCallable[testproto.test_no_generic_services_pb2.Simple3, testproto.test_no_generic_services_pb2.Simple3] 19 | 20 | class ATestService2Servicer(metaclass=abc.ABCMeta): 21 | @abc.abstractmethod 22 | def Echo( 23 | self, 24 | request: testproto.test_no_generic_services_pb2.Simple3, 25 | context: grpc.ServicerContext, 26 | ) -> testproto.test_no_generic_services_pb2.Simple3: ... 27 | 28 | def add_ATestService2Servicer_to_server(servicer: ATestService2Servicer, server: grpc.Server) -> None: ... 29 | -------------------------------------------------------------------------------- /test/generated/testproto/dot/com/test_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class TestMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | FOO_FIELD_NUMBER: builtins.int 24 | foo: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | foo: builtins.str = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["foo", b"foo"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___TestMessage: typing_extensions.TypeAlias = TestMessage 34 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/dot/com/test_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class TestMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | FOO_FIELD_NUMBER: builtins.int 24 | foo: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | foo: builtins.str = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["foo", b"foo"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___TestMessage: typing_extensions.TypeAlias = TestMessage 34 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/dot/com/test_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class TestMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | FOO_FIELD_NUMBER: builtins.int 24 | foo: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | foo: builtins.str = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["foo", b"foo"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___TestMessage: typing_extensions.TypeAlias = TestMessage 34 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/dot/com/test_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class TestMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | FOO_FIELD_NUMBER: builtins.int 24 | foo: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | foo: builtins.str = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["foo", b"foo"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___TestMessage: typing_extensions.TypeAlias = TestMessage 34 | -------------------------------------------------------------------------------- /test/generated/testproto/inner/inner_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import testproto.test3_pb2 11 | import typing 12 | 13 | if sys.version_info >= (3, 10): 14 | import typing as typing_extensions 15 | else: 16 | import typing_extensions 17 | 18 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 19 | 20 | @typing.final 21 | class Inner(google.protobuf.message.Message): 22 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 23 | 24 | A_FIELD_NUMBER: builtins.int 25 | a: testproto.test3_pb2.OuterEnum.ValueType 26 | def __init__( 27 | self, 28 | *, 29 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 30 | ) -> None: ... 31 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 32 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 33 | 34 | Global___Inner: typing_extensions.TypeAlias = Inner 35 | -------------------------------------------------------------------------------- /test/generated/testproto/readme_enum_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | class _MyEnum: 20 | ValueType = typing.NewType("ValueType", builtins.int) 21 | V: typing_extensions.TypeAlias = ValueType 22 | 23 | class _MyEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_MyEnum.ValueType], builtins.type): 24 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 25 | HELLO: _MyEnum.ValueType # 0 26 | WORLD: _MyEnum.ValueType # 1 27 | 28 | class MyEnum(_MyEnum, metaclass=_MyEnumEnumTypeWrapper): ... 29 | 30 | HELLO: MyEnum.ValueType # 0 31 | WORLD: MyEnum.ValueType # 1 32 | Global___MyEnum: typing_extensions.TypeAlias = MyEnum 33 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/inner/inner_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import testproto.test3_pb2 11 | import typing 12 | 13 | if sys.version_info >= (3, 10): 14 | import typing as typing_extensions 15 | else: 16 | import typing_extensions 17 | 18 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 19 | 20 | @typing.final 21 | class Inner(google.protobuf.message.Message): 22 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 23 | 24 | A_FIELD_NUMBER: builtins.int 25 | a: testproto.test3_pb2.OuterEnum.ValueType 26 | def __init__( 27 | self, 28 | *, 29 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 30 | ) -> None: ... 31 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 32 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 33 | 34 | Global___Inner: typing_extensions.TypeAlias = Inner 35 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/inner/inner_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import testproto.test3_pb2 11 | import typing 12 | 13 | if sys.version_info >= (3, 10): 14 | import typing as typing_extensions 15 | else: 16 | import typing_extensions 17 | 18 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 19 | 20 | @typing.final 21 | class Inner(google.protobuf.message.Message): 22 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 23 | 24 | A_FIELD_NUMBER: builtins.int 25 | a: testproto.test3_pb2.OuterEnum.ValueType 26 | def __init__( 27 | self, 28 | *, 29 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 30 | ) -> None: ... 31 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 32 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 33 | 34 | Global___Inner: typing_extensions.TypeAlias = Inner 35 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/inner/inner_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import testproto.test3_pb2 11 | import typing 12 | 13 | if sys.version_info >= (3, 10): 14 | import typing as typing_extensions 15 | else: 16 | import typing_extensions 17 | 18 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 19 | 20 | @typing.final 21 | class Inner(google.protobuf.message.Message): 22 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 23 | 24 | A_FIELD_NUMBER: builtins.int 25 | a: testproto.test3_pb2.OuterEnum.ValueType 26 | def __init__( 27 | self, 28 | *, 29 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 30 | ) -> None: ... 31 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 32 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 33 | 34 | Global___Inner: typing_extensions.TypeAlias = Inner 35 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/readme_enum_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | class _MyEnum: 20 | ValueType = typing.NewType("ValueType", builtins.int) 21 | V: typing_extensions.TypeAlias = ValueType 22 | 23 | class _MyEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_MyEnum.ValueType], builtins.type): 24 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 25 | HELLO: _MyEnum.ValueType # 0 26 | WORLD: _MyEnum.ValueType # 1 27 | 28 | class MyEnum(_MyEnum, metaclass=_MyEnumEnumTypeWrapper): ... 29 | 30 | HELLO: MyEnum.ValueType # 0 31 | WORLD: MyEnum.ValueType # 1 32 | Global___MyEnum: typing_extensions.TypeAlias = MyEnum 33 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/readme_enum_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | class _MyEnum: 20 | ValueType = typing.NewType("ValueType", builtins.int) 21 | V: typing_extensions.TypeAlias = ValueType 22 | 23 | class _MyEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_MyEnum.ValueType], builtins.type): 24 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 25 | HELLO: _MyEnum.ValueType # 0 26 | WORLD: _MyEnum.ValueType # 1 27 | 28 | class MyEnum(_MyEnum, metaclass=_MyEnumEnumTypeWrapper): ... 29 | 30 | HELLO: MyEnum.ValueType # 0 31 | WORLD: MyEnum.ValueType # 1 32 | Global___MyEnum: typing_extensions.TypeAlias = MyEnum 33 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/readme_enum_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | class _MyEnum: 20 | ValueType = typing.NewType("ValueType", builtins.int) 21 | V: typing_extensions.TypeAlias = ValueType 22 | 23 | class _MyEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_MyEnum.ValueType], builtins.type): 24 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 25 | HELLO: _MyEnum.ValueType # 0 26 | WORLD: _MyEnum.ValueType # 1 27 | 28 | class MyEnum(_MyEnum, metaclass=_MyEnumEnumTypeWrapper): ... 29 | 30 | HELLO: MyEnum.ValueType # 0 31 | WORLD: MyEnum.ValueType # 1 32 | Global___MyEnum: typing_extensions.TypeAlias = MyEnum 33 | -------------------------------------------------------------------------------- /proto/testproto/comment_special_chars.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package comment_special_chars; 4 | 5 | message Test { 6 | // Ending with " 7 | string a = 1; 8 | // Ending with "" 9 | string b = 2; 10 | // Ending with """ 11 | string c = 3; 12 | // Ending with \ 13 | string d = 4; 14 | // Containing bad escape: \x 15 | string e = 5; 16 | // Containing """" quadruple 17 | string f = 6; 18 | // Containing """"" quintuple 19 | string g = 7; 20 | // Containing """""" sextuple 21 | string h = 8; 22 | // """ Multiple """ triples """ 23 | string i = 9; 24 | // "quotes" can be a problem in comments. 25 | // """Triple quotes""" just as well 26 | string j = 10; 27 | // """""""""""""""""""""""""""""""""""""""""""""""" 28 | // " " 29 | // " Super Duper comments with surrounding edges! " 30 | // " " 31 | // " Pay attention to me!!!! " 32 | // " " 33 | // """""""""""""""""""""""""""""""""""""""""""""""" 34 | string k = 11; 35 | } 36 | -------------------------------------------------------------------------------- /proto/testproto/test_extensions3.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "google/protobuf/descriptor.proto"; 4 | import "testproto/test3.proto"; 5 | 6 | package test3; 7 | 8 | extend google.protobuf.FieldOptions { 9 | string test_field_extension = 50000; 10 | } 11 | 12 | extend google.protobuf.MessageOptions { 13 | string scalar_option = 51234; 14 | repeated string repeated_scalar_option = 51235; 15 | OuterEnum enum_option = 51236; 16 | repeated OuterEnum repeated_enum_option = 51237; 17 | OuterMessage3 msg_option = 51238; 18 | repeated OuterMessage3 repeated_msg_option = 51239; 19 | } 20 | 21 | message MessageOptionsTestMsg { 22 | option (scalar_option) = "Hello world!"; 23 | option (repeated_scalar_option) = "A"; 24 | option (repeated_scalar_option) = "B"; 25 | option (repeated_scalar_option) = "C"; 26 | 27 | option (enum_option) = FOO3; 28 | option (repeated_enum_option) = FOO3; 29 | option (repeated_enum_option) = BAR3; 30 | 31 | option (msg_option).a_string = "Hello OuterMessage3"; 32 | option (repeated_msg_option) = {a_string: "Hello OuterMessage3 A"}; 33 | option (repeated_msg_option) = {a_string: "Hello OuterMessage3 B"}; 34 | } 35 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_no_generic_services_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import grpc 9 | import grpc.aio 10 | import testproto.test_no_generic_services_pb2 11 | import typing 12 | 13 | 14 | GRPC_GENERATED_VERSION: str 15 | GRPC_VERSION: str 16 | 17 | class ATestService2Stub: 18 | def __init__(self, channel: grpc.aio.Channel) -> None: ... 19 | Echo: grpc.aio.UnaryUnaryMultiCallable[testproto.test_no_generic_services_pb2.Simple3, testproto.test_no_generic_services_pb2.Simple3] 20 | 21 | class ATestService2Servicer(metaclass=abc.ABCMeta): 22 | @abc.abstractmethod 23 | def Echo( 24 | self, 25 | request: testproto.test_no_generic_services_pb2.Simple3, 26 | context: grpc.aio.ServicerContext[testproto.test_no_generic_services_pb2.Simple3, collections.abc.Awaitable[testproto.test_no_generic_services_pb2.Simple3]], 27 | ) -> collections.abc.Awaitable[testproto.test_no_generic_services_pb2.Simple3]: ... 28 | 29 | def add_ATestService2Servicer_to_server(servicer: ATestService2Servicer, server: grpc.aio.Server) -> None: ... 30 | -------------------------------------------------------------------------------- /test/generated/testproto/test_no_generic_services_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Simple3(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_STRING_FIELD_NUMBER: builtins.int 24 | a_string: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | a_string: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Simple3: typing_extensions.TypeAlias = Simple3 36 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/test_no_generic_services_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Simple3(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_STRING_FIELD_NUMBER: builtins.int 24 | a_string: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | a_string: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Simple3: typing_extensions.TypeAlias = Simple3 36 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_no_generic_services_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Simple3(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_STRING_FIELD_NUMBER: builtins.int 24 | a_string: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | a_string: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Simple3: typing_extensions.TypeAlias = Simple3 36 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_no_generic_services_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Simple3(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_STRING_FIELD_NUMBER: builtins.int 24 | a_string: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | a_string: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Simple3: typing_extensions.TypeAlias = Simple3 36 | -------------------------------------------------------------------------------- /test/generated/testproto/test_extensions2_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.extension_dict 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class SeparateFileExtension(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | FLAG_FIELD_NUMBER: builtins.int 26 | flag: builtins.bool 27 | EXT_FIELD_NUMBER: builtins.int 28 | ext: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[testproto.test_pb2.Simple2, Global___SeparateFileExtension] 29 | def __init__( 30 | self, 31 | *, 32 | flag: builtins.bool | None = ..., 33 | ) -> None: ... 34 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 35 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 36 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 37 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 38 | 39 | Global___SeparateFileExtension: typing_extensions.TypeAlias = SeparateFileExtension 40 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/test_extensions2_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.extension_dict 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class SeparateFileExtension(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | FLAG_FIELD_NUMBER: builtins.int 26 | flag: builtins.bool 27 | EXT_FIELD_NUMBER: builtins.int 28 | ext: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[testproto.test_pb2.Simple2, Global___SeparateFileExtension] 29 | def __init__( 30 | self, 31 | *, 32 | flag: builtins.bool | None = ..., 33 | ) -> None: ... 34 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 35 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 36 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 37 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 38 | 39 | Global___SeparateFileExtension: typing_extensions.TypeAlias = SeparateFileExtension 40 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_extensions2_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.extension_dict 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class SeparateFileExtension(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | FLAG_FIELD_NUMBER: builtins.int 26 | flag: builtins.bool 27 | EXT_FIELD_NUMBER: builtins.int 28 | ext: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[testproto.test_pb2.Simple2, Global___SeparateFileExtension] 29 | def __init__( 30 | self, 31 | *, 32 | flag: builtins.bool | None = ..., 33 | ) -> None: ... 34 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 35 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 36 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 37 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 38 | 39 | Global___SeparateFileExtension: typing_extensions.TypeAlias = SeparateFileExtension 40 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_extensions2_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.extension_dict 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class SeparateFileExtension(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | FLAG_FIELD_NUMBER: builtins.int 26 | flag: builtins.bool 27 | EXT_FIELD_NUMBER: builtins.int 28 | ext: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[testproto.test_pb2.Simple2, Global___SeparateFileExtension] 29 | def __init__( 30 | self, 31 | *, 32 | flag: builtins.bool | None = ..., 33 | ) -> None: ... 34 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 35 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 36 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["flag", b"flag"] 37 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 38 | 39 | Global___SeparateFileExtension: typing_extensions.TypeAlias = SeparateFileExtension 40 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Proto 2 test file.""" 5 | 6 | import abc 7 | import collections.abc 8 | import grpc 9 | import testproto.test_pb2 10 | import typing 11 | 12 | 13 | GRPC_GENERATED_VERSION: str 14 | GRPC_VERSION: str 15 | 16 | class PythonReservedKeywordsServiceStub: 17 | """Method name is reserved""" 18 | 19 | def __init__(self, channel: grpc.Channel) -> None: ... 20 | valid_method_name1: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, testproto.test_pb2._r_None] 21 | """valid_method_name1""" 22 | valid_method_name2: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, testproto.test_pb2.PythonReservedKeywords._r_lambda] 23 | """valid_method_name2""" 24 | 25 | class PythonReservedKeywordsServiceServicer(metaclass=abc.ABCMeta): 26 | """Method name is reserved""" 27 | 28 | @abc.abstractmethod 29 | def valid_method_name1( 30 | self, 31 | request: testproto.test_pb2.Simple1, 32 | context: grpc.ServicerContext, 33 | ) -> testproto.test_pb2._r_None: 34 | """valid_method_name1""" 35 | 36 | @abc.abstractmethod 37 | def valid_method_name2( 38 | self, 39 | request: testproto.test_pb2.Simple1, 40 | context: grpc.ServicerContext, 41 | ) -> testproto.test_pb2.PythonReservedKeywords._r_lambda: 42 | """valid_method_name2""" 43 | 44 | def add_PythonReservedKeywordsServiceServicer_to_server(servicer: PythonReservedKeywordsServiceServicer, server: grpc.Server) -> None: ... 45 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel", 5 | ] 6 | build-backend = "setuptools.build_meta" 7 | 8 | [tool.black] 9 | extend-exclude = "(_pb2.py$|_pb2_grpc.py$)" 10 | # We don't care about line length for generated code 11 | line-length = 10000 12 | 13 | [tool.isort] 14 | profile = "black" 15 | skip_gitignore = true 16 | extend_skip_glob = ["*_pb2.py", "*_pb2_grpc.py"] 17 | 18 | [tool.mypy] 19 | strict = true 20 | show_error_codes = true 21 | enable_error_code = ["deprecated"] 22 | 23 | [tool.pyright] 24 | venvPath = "." 25 | venv = "venv_3.14.0" 26 | # verboseOutput = true 27 | extraPaths = ["test/generated"] 28 | include = [ 29 | "mypy_protobuf/", 30 | "test/" 31 | ] 32 | exclude = [ 33 | "**/*_pb2.py", 34 | "**/*_pb2_grpc.py", 35 | "test/test_concrete.py", 36 | ] 37 | 38 | executionEnvironments = [ 39 | # Due to how upb is typed, we need to disable incompatible variable override checks 40 | { root = "test/generated", extraPaths = ["./"], reportIncompatibleVariableOverride = "none" }, 41 | { root = "test/generated_concrete", extraPaths = ["./"], reportIncompatibleVariableOverride = "none" }, 42 | { root = "test/generated_sync_only", extraPaths = ["./"], reportIncompatibleVariableOverride = "none" }, 43 | { root = "test/generated_async_only", extraPaths = ["./"], reportIncompatibleVariableOverride = "none" }, 44 | { root = "mypy_protobuf/extensions_pb2.pyi", reportIncompatibleVariableOverride = "none" }, 45 | { root = "test/async_only", extraPaths = ["test/generated_async_only"] }, 46 | { root = "test/sync_only", extraPaths = ["test/generated_sync_only"] }, 47 | ] 48 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/grpc/import_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import google.protobuf.empty_pb2 9 | import grpc 10 | import testproto.test_pb2 11 | import typing 12 | 13 | 14 | GRPC_GENERATED_VERSION: str 15 | GRPC_VERSION: str 16 | 17 | class SimpleServiceStub: 18 | """SimpleService""" 19 | 20 | def __init__(self, channel: grpc.Channel) -> None: ... 21 | UnaryUnary: grpc.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] 22 | """UnaryUnary""" 23 | UnaryStream: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 24 | """UnaryStream""" 25 | NoComment: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 26 | 27 | class SimpleServiceServicer(metaclass=abc.ABCMeta): 28 | """SimpleService""" 29 | 30 | @abc.abstractmethod 31 | def UnaryUnary( 32 | self, 33 | request: google.protobuf.empty_pb2.Empty, 34 | context: grpc.ServicerContext, 35 | ) -> testproto.test_pb2.Simple1: 36 | """UnaryUnary""" 37 | 38 | @abc.abstractmethod 39 | def UnaryStream( 40 | self, 41 | request: testproto.test_pb2.Simple1, 42 | context: grpc.ServicerContext, 43 | ) -> google.protobuf.empty_pb2.Empty: 44 | """UnaryStream""" 45 | 46 | @abc.abstractmethod 47 | def NoComment( 48 | self, 49 | request: testproto.test_pb2.Simple1, 50 | context: grpc.ServicerContext, 51 | ) -> google.protobuf.empty_pb2.Empty: ... 52 | 53 | def add_SimpleServiceServicer_to_server(servicer: SimpleServiceServicer, server: grpc.Server) -> None: ... 54 | -------------------------------------------------------------------------------- /proto/testproto/test3.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Proto 3 test example. 3 | * 4 | * Descriptor documentation should show up in module docstrings. 5 | */ 6 | syntax = "proto3"; 7 | 8 | /* package test3 */ 9 | package test3; 10 | 11 | import "mypy_protobuf/extensions.proto"; 12 | 13 | enum OuterEnum { 14 | UNKNOWN = 0; 15 | FOO3 = 1; 16 | BAR3 = 2; 17 | } 18 | 19 | message OuterMessage3 { 20 | string a_string = 1; 21 | } 22 | 23 | message SimpleProto3 { 24 | enum InnerEnum { 25 | INNER1 = 0; 26 | INNER2 = 1; 27 | } 28 | 29 | string a_string = 1; 30 | repeated string a_repeated_string = 2; 31 | OuterEnum a_outer_enum = 3; 32 | OuterMessage3 outer_message = 4; 33 | InnerEnum inner_enum = 15; 34 | 35 | oneof a_oneof { 36 | string a_oneof_1 = 5; 37 | string a_oneof_2 = 6; 38 | OuterMessage3 outer_message_in_oneof = 12; 39 | OuterEnum outer_enum_in_oneof = 13; 40 | InnerEnum inner_enum_in_oneof = 14; 41 | } 42 | 43 | oneof b_oneof { 44 | string b_oneof_1 = 7; 45 | string b_oneof_2 = 8; 46 | } 47 | 48 | OuterMessage3 bool = 9; 49 | 50 | // Test having fieldname match messagename 51 | OuterEnum OuterEnum = 10; 52 | OuterMessage3 OuterMessage3 = 11; 53 | 54 | // Test generation of map 55 | map map_scalar = 16; 56 | map map_message = 17; 57 | 58 | optional string an_optional_string = 18; 59 | 60 | uint32 user_id = 19 [(mypy_protobuf.options).casttype="test/test_generated_mypy.UserId"]; 61 | string email = 20 [(mypy_protobuf.options).casttype="test/test_generated_mypy.Email"]; 62 | map email_by_uid = 21 [ 63 | (mypy_protobuf.options).keytype="test/test_generated_mypy.UserId", 64 | (mypy_protobuf.options).valuetype="test/test_generated_mypy.Email" 65 | ]; 66 | } 67 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Proto 2 test file.""" 5 | 6 | import abc 7 | import collections.abc 8 | import grpc 9 | import grpc.aio 10 | import testproto.test_pb2 11 | import typing 12 | 13 | 14 | GRPC_GENERATED_VERSION: str 15 | GRPC_VERSION: str 16 | 17 | class PythonReservedKeywordsServiceStub: 18 | """Method name is reserved""" 19 | 20 | def __init__(self, channel: grpc.aio.Channel) -> None: ... 21 | valid_method_name1: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, testproto.test_pb2._r_None] 22 | """valid_method_name1""" 23 | valid_method_name2: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, testproto.test_pb2.PythonReservedKeywords._r_lambda] 24 | """valid_method_name2""" 25 | 26 | class PythonReservedKeywordsServiceServicer(metaclass=abc.ABCMeta): 27 | """Method name is reserved""" 28 | 29 | @abc.abstractmethod 30 | def valid_method_name1( 31 | self, 32 | request: testproto.test_pb2.Simple1, 33 | context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[testproto.test_pb2._r_None]], 34 | ) -> collections.abc.Awaitable[testproto.test_pb2._r_None]: 35 | """valid_method_name1""" 36 | 37 | @abc.abstractmethod 38 | def valid_method_name2( 39 | self, 40 | request: testproto.test_pb2.Simple1, 41 | context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[testproto.test_pb2.PythonReservedKeywords._r_lambda]], 42 | ) -> collections.abc.Awaitable[testproto.test_pb2.PythonReservedKeywords._r_lambda]: 43 | """valid_method_name2""" 44 | 45 | def add_PythonReservedKeywordsServiceServicer_to_server(servicer: PythonReservedKeywordsServiceServicer, server: grpc.aio.Server) -> None: ... 46 | -------------------------------------------------------------------------------- /test/generated/testproto/nopackage_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class NoPackage(google.protobuf.message.Message): 23 | """Intentionally don't set a package - just to make sure we can handle it.""" 24 | 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___NoPackage: typing_extensions.TypeAlias = NoPackage 32 | 33 | @typing.final 34 | class NoPackage2(google.protobuf.message.Message): 35 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 36 | 37 | NP_FIELD_NUMBER: builtins.int 38 | NP_REP_FIELD_NUMBER: builtins.int 39 | @property 40 | def np(self) -> Global___NoPackage: ... 41 | @property 42 | def np_rep(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[Global___NoPackage]: ... 43 | def __init__( 44 | self, 45 | *, 46 | np: Global___NoPackage | None = ..., 47 | np_rep: collections.abc.Iterable[Global___NoPackage] | None = ..., 48 | ) -> None: ... 49 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np"] 50 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np", "np_rep", b"np_rep"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___NoPackage2: typing_extensions.TypeAlias = NoPackage2 55 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/nopackage_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class NoPackage(google.protobuf.message.Message): 23 | """Intentionally don't set a package - just to make sure we can handle it.""" 24 | 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___NoPackage: typing_extensions.TypeAlias = NoPackage 32 | 33 | @typing.final 34 | class NoPackage2(google.protobuf.message.Message): 35 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 36 | 37 | NP_FIELD_NUMBER: builtins.int 38 | NP_REP_FIELD_NUMBER: builtins.int 39 | @property 40 | def np(self) -> Global___NoPackage: ... 41 | @property 42 | def np_rep(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[Global___NoPackage]: ... 43 | def __init__( 44 | self, 45 | *, 46 | np: Global___NoPackage | None = ..., 47 | np_rep: collections.abc.Iterable[Global___NoPackage] | None = ..., 48 | ) -> None: ... 49 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np"] 50 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np", "np_rep", b"np_rep"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___NoPackage2: typing_extensions.TypeAlias = NoPackage2 55 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/nopackage_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class NoPackage(google.protobuf.message.Message): 23 | """Intentionally don't set a package - just to make sure we can handle it.""" 24 | 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___NoPackage: typing_extensions.TypeAlias = NoPackage 32 | 33 | @typing.final 34 | class NoPackage2(google.protobuf.message.Message): 35 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 36 | 37 | NP_FIELD_NUMBER: builtins.int 38 | NP_REP_FIELD_NUMBER: builtins.int 39 | @property 40 | def np(self) -> Global___NoPackage: ... 41 | @property 42 | def np_rep(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[Global___NoPackage]: ... 43 | def __init__( 44 | self, 45 | *, 46 | np: Global___NoPackage | None = ..., 47 | np_rep: collections.abc.Iterable[Global___NoPackage] | None = ..., 48 | ) -> None: ... 49 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np"] 50 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np", "np_rep", b"np_rep"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___NoPackage2: typing_extensions.TypeAlias = NoPackage2 55 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/nopackage_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class NoPackage(google.protobuf.message.Message): 23 | """Intentionally don't set a package - just to make sure we can handle it.""" 24 | 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___NoPackage: typing_extensions.TypeAlias = NoPackage 32 | 33 | @typing.final 34 | class NoPackage2(google.protobuf.message.Message): 35 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 36 | 37 | NP_FIELD_NUMBER: builtins.int 38 | NP_REP_FIELD_NUMBER: builtins.int 39 | @property 40 | def np(self) -> Global___NoPackage: ... 41 | @property 42 | def np_rep(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[Global___NoPackage]: ... 43 | def __init__( 44 | self, 45 | *, 46 | np: Global___NoPackage | None = ..., 47 | np_rep: collections.abc.Iterable[Global___NoPackage] | None = ..., 48 | ) -> None: ... 49 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np"] 50 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["np", b"np", "np_rep", b"np_rep"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___NoPackage2: typing_extensions.TypeAlias = NoPackage2 55 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/grpc/import_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import google.protobuf.empty_pb2 9 | import grpc 10 | import grpc.aio 11 | import testproto.test_pb2 12 | import typing 13 | 14 | 15 | GRPC_GENERATED_VERSION: str 16 | GRPC_VERSION: str 17 | 18 | class SimpleServiceStub: 19 | """SimpleService""" 20 | 21 | def __init__(self, channel: grpc.aio.Channel) -> None: ... 22 | UnaryUnary: grpc.aio.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] 23 | """UnaryUnary""" 24 | UnaryStream: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 25 | """UnaryStream""" 26 | NoComment: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 27 | 28 | class SimpleServiceServicer(metaclass=abc.ABCMeta): 29 | """SimpleService""" 30 | 31 | @abc.abstractmethod 32 | def UnaryUnary( 33 | self, 34 | request: google.protobuf.empty_pb2.Empty, 35 | context: grpc.aio.ServicerContext[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[testproto.test_pb2.Simple1]], 36 | ) -> collections.abc.Awaitable[testproto.test_pb2.Simple1]: 37 | """UnaryUnary""" 38 | 39 | @abc.abstractmethod 40 | def UnaryStream( 41 | self, 42 | request: testproto.test_pb2.Simple1, 43 | context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]], 44 | ) -> collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]: 45 | """UnaryStream""" 46 | 47 | @abc.abstractmethod 48 | def NoComment( 49 | self, 50 | request: testproto.test_pb2.Simple1, 51 | context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]], 52 | ) -> collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]: ... 53 | 54 | def add_SimpleServiceServicer_to_server(servicer: SimpleServiceServicer, server: grpc.aio.Server) -> None: ... 55 | -------------------------------------------------------------------------------- /mypy_protobuf/extensions_pb2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | # NO CHECKED-IN PROTOBUF GENCODE 4 | # source: mypy_protobuf/extensions.proto 5 | # Protobuf Python Version: 6.32.1 6 | """Generated protocol buffer code.""" 7 | from google.protobuf import descriptor as _descriptor 8 | from google.protobuf import descriptor_pool as _descriptor_pool 9 | from google.protobuf import runtime_version as _runtime_version 10 | from google.protobuf import symbol_database as _symbol_database 11 | from google.protobuf.internal import builder as _builder 12 | _runtime_version.ValidateProtobufRuntimeVersion( 13 | _runtime_version.Domain.PUBLIC, 14 | 6, 15 | 32, 16 | 1, 17 | '', 18 | 'mypy_protobuf/extensions.proto' 19 | ) 20 | # @@protoc_insertion_point(imports) 21 | 22 | _sym_db = _symbol_database.Default() 23 | 24 | 25 | from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2 26 | 27 | 28 | DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1emypy_protobuf/extensions.proto\x12\rmypy_protobuf\x1a google/protobuf/descriptor.proto\"D\n\x0c\x46ieldOptions\x12\x10\n\x08\x63\x61sttype\x18\x01 \x01(\t\x12\x0f\n\x07keytype\x18\x02 \x01(\t\x12\x11\n\tvaluetype\x18\x03 \x01(\t:L\n\x07options\x12\x1d.google.protobuf.FieldOptions\x18\x82\t \x01(\x0b\x32\x1b.mypy_protobuf.FieldOptions:4\n\x08\x63\x61sttype\x12\x1d.google.protobuf.FieldOptions\x18\xff\x08 \x01(\tB\x02\x18\x01:3\n\x07keytype\x12\x1d.google.protobuf.FieldOptions\x18\x80\t \x01(\tB\x02\x18\x01:5\n\tvaluetype\x12\x1d.google.protobuf.FieldOptions\x18\x81\t \x01(\tB\x02\x18\x01\x62\x06proto3') 29 | 30 | _globals = globals() 31 | _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) 32 | _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mypy_protobuf.extensions_pb2', _globals) 33 | if not _descriptor._USE_C_DESCRIPTORS: 34 | DESCRIPTOR._loaded_options = None 35 | _globals['casttype']._loaded_options = None 36 | _globals['casttype']._serialized_options = b'\030\001' 37 | _globals['keytype']._loaded_options = None 38 | _globals['keytype']._serialized_options = b'\030\001' 39 | _globals['valuetype']._loaded_options = None 40 | _globals['valuetype']._serialized_options = b'\030\001' 41 | _globals['_FIELDOPTIONS']._serialized_start=83 42 | _globals['_FIELDOPTIONS']._serialized_end=151 43 | # @@protoc_insertion_point(module_scope) 44 | -------------------------------------------------------------------------------- /test/generated/testproto/Capitalized/Capitalized_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class lower(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | a: builtins.int 25 | def __init__( 26 | self, 27 | *, 28 | a: builtins.int = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___lower: typing_extensions.TypeAlias = lower 34 | 35 | @typing.final 36 | class Upper(google.protobuf.message.Message): 37 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 38 | 39 | LOWER_FIELD_NUMBER: builtins.int 40 | @property 41 | def Lower(self) -> Global___lower: ... 42 | def __init__( 43 | self, 44 | *, 45 | Lower: Global___lower | None = ..., 46 | ) -> None: ... 47 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 48 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 49 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 50 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 51 | 52 | Global___Upper: typing_extensions.TypeAlias = Upper 53 | 54 | @typing.final 55 | class lower2(google.protobuf.message.Message): 56 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 57 | 58 | UPPER_FIELD_NUMBER: builtins.int 59 | @property 60 | def upper(self) -> Global___Upper: ... 61 | def __init__( 62 | self, 63 | *, 64 | upper: Global___Upper | None = ..., 65 | ) -> None: ... 66 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 67 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 68 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 69 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 70 | 71 | Global___lower2: typing_extensions.TypeAlias = lower2 72 | -------------------------------------------------------------------------------- /mypy_protobuf/extensions_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.extension_dict 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class FieldOptions(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | CASTTYPE_FIELD_NUMBER: builtins.int 26 | KEYTYPE_FIELD_NUMBER: builtins.int 27 | VALUETYPE_FIELD_NUMBER: builtins.int 28 | casttype: builtins.str 29 | """Tells mypy-protobuf to use a specific newtype rather than the normal type for this field.""" 30 | keytype: builtins.str 31 | """Tells mypy-protobuf to use a specific type for keys; only makes sense on map fields""" 32 | valuetype: builtins.str 33 | """Tells mypy-protobuf to use a specific type for values; only makes sense on map fields""" 34 | def __init__( 35 | self, 36 | *, 37 | casttype: builtins.str = ..., 38 | keytype: builtins.str = ..., 39 | valuetype: builtins.str = ..., 40 | ) -> None: ... 41 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["casttype", b"casttype", "keytype", b"keytype", "valuetype", b"valuetype"] 42 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 43 | 44 | Global___FieldOptions: typing_extensions.TypeAlias = FieldOptions 45 | 46 | OPTIONS_FIELD_NUMBER: builtins.int 47 | CASTTYPE_FIELD_NUMBER: builtins.int 48 | KEYTYPE_FIELD_NUMBER: builtins.int 49 | VALUETYPE_FIELD_NUMBER: builtins.int 50 | options: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, Global___FieldOptions] 51 | """Custom field options from mypy-protobuf""" 52 | casttype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 53 | """Legacy fields. Prefer to use ones within `options` instead.""" 54 | keytype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 55 | valuetype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 56 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/Capitalized/Capitalized_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class lower(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | a: builtins.int 25 | def __init__( 26 | self, 27 | *, 28 | a: builtins.int = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___lower: typing_extensions.TypeAlias = lower 34 | 35 | @typing.final 36 | class Upper(google.protobuf.message.Message): 37 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 38 | 39 | LOWER_FIELD_NUMBER: builtins.int 40 | @property 41 | def Lower(self) -> Global___lower: ... 42 | def __init__( 43 | self, 44 | *, 45 | Lower: Global___lower | None = ..., 46 | ) -> None: ... 47 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 48 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 49 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 50 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 51 | 52 | Global___Upper: typing_extensions.TypeAlias = Upper 53 | 54 | @typing.final 55 | class lower2(google.protobuf.message.Message): 56 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 57 | 58 | UPPER_FIELD_NUMBER: builtins.int 59 | @property 60 | def upper(self) -> Global___Upper: ... 61 | def __init__( 62 | self, 63 | *, 64 | upper: Global___Upper | None = ..., 65 | ) -> None: ... 66 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 67 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 68 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 69 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 70 | 71 | Global___lower2: typing_extensions.TypeAlias = lower2 72 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/Capitalized/Capitalized_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class lower(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | a: builtins.int 25 | def __init__( 26 | self, 27 | *, 28 | a: builtins.int = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___lower: typing_extensions.TypeAlias = lower 34 | 35 | @typing.final 36 | class Upper(google.protobuf.message.Message): 37 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 38 | 39 | LOWER_FIELD_NUMBER: builtins.int 40 | @property 41 | def Lower(self) -> Global___lower: ... 42 | def __init__( 43 | self, 44 | *, 45 | Lower: Global___lower | None = ..., 46 | ) -> None: ... 47 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 48 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 49 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 50 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 51 | 52 | Global___Upper: typing_extensions.TypeAlias = Upper 53 | 54 | @typing.final 55 | class lower2(google.protobuf.message.Message): 56 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 57 | 58 | UPPER_FIELD_NUMBER: builtins.int 59 | @property 60 | def upper(self) -> Global___Upper: ... 61 | def __init__( 62 | self, 63 | *, 64 | upper: Global___Upper | None = ..., 65 | ) -> None: ... 66 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 67 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 68 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 69 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 70 | 71 | Global___lower2: typing_extensions.TypeAlias = lower2 72 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/Capitalized/Capitalized_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class lower(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | a: builtins.int 25 | def __init__( 26 | self, 27 | *, 28 | a: builtins.int = ..., 29 | ) -> None: ... 30 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 31 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 32 | 33 | Global___lower: typing_extensions.TypeAlias = lower 34 | 35 | @typing.final 36 | class Upper(google.protobuf.message.Message): 37 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 38 | 39 | LOWER_FIELD_NUMBER: builtins.int 40 | @property 41 | def Lower(self) -> Global___lower: ... 42 | def __init__( 43 | self, 44 | *, 45 | Lower: Global___lower | None = ..., 46 | ) -> None: ... 47 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 48 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 49 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["Lower", b"Lower"] 50 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 51 | 52 | Global___Upper: typing_extensions.TypeAlias = Upper 53 | 54 | @typing.final 55 | class lower2(google.protobuf.message.Message): 56 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 57 | 58 | UPPER_FIELD_NUMBER: builtins.int 59 | @property 60 | def upper(self) -> Global___Upper: ... 61 | def __init__( 62 | self, 63 | *, 64 | upper: Global___Upper | None = ..., 65 | ) -> None: ... 66 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 67 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 68 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["upper", b"upper"] 69 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 70 | 71 | Global___lower2: typing_extensions.TypeAlias = lower2 72 | -------------------------------------------------------------------------------- /test/generated/mypy_protobuf/extensions_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.extension_dict 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class FieldOptions(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | CASTTYPE_FIELD_NUMBER: builtins.int 26 | KEYTYPE_FIELD_NUMBER: builtins.int 27 | VALUETYPE_FIELD_NUMBER: builtins.int 28 | casttype: builtins.str 29 | """Tells mypy-protobuf to use a specific newtype rather than the normal type for this field.""" 30 | keytype: builtins.str 31 | """Tells mypy-protobuf to use a specific type for keys; only makes sense on map fields""" 32 | valuetype: builtins.str 33 | """Tells mypy-protobuf to use a specific type for values; only makes sense on map fields""" 34 | def __init__( 35 | self, 36 | *, 37 | casttype: builtins.str = ..., 38 | keytype: builtins.str = ..., 39 | valuetype: builtins.str = ..., 40 | ) -> None: ... 41 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["casttype", b"casttype", "keytype", b"keytype", "valuetype", b"valuetype"] 42 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 43 | 44 | Global___FieldOptions: typing_extensions.TypeAlias = FieldOptions 45 | 46 | OPTIONS_FIELD_NUMBER: builtins.int 47 | CASTTYPE_FIELD_NUMBER: builtins.int 48 | KEYTYPE_FIELD_NUMBER: builtins.int 49 | VALUETYPE_FIELD_NUMBER: builtins.int 50 | options: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, Global___FieldOptions] 51 | """Custom field options from mypy-protobuf""" 52 | casttype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 53 | """Legacy fields. Prefer to use ones within `options` instead.""" 54 | keytype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 55 | valuetype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 56 | -------------------------------------------------------------------------------- /test/generated_concrete/mypy_protobuf/extensions_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.extension_dict 10 | import google.protobuf.message 11 | import sys 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class FieldOptions(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | CASTTYPE_FIELD_NUMBER: builtins.int 26 | KEYTYPE_FIELD_NUMBER: builtins.int 27 | VALUETYPE_FIELD_NUMBER: builtins.int 28 | casttype: builtins.str 29 | """Tells mypy-protobuf to use a specific newtype rather than the normal type for this field.""" 30 | keytype: builtins.str 31 | """Tells mypy-protobuf to use a specific type for keys; only makes sense on map fields""" 32 | valuetype: builtins.str 33 | """Tells mypy-protobuf to use a specific type for values; only makes sense on map fields""" 34 | def __init__( 35 | self, 36 | *, 37 | casttype: builtins.str = ..., 38 | keytype: builtins.str = ..., 39 | valuetype: builtins.str = ..., 40 | ) -> None: ... 41 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["casttype", b"casttype", "keytype", b"keytype", "valuetype", b"valuetype"] 42 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 43 | 44 | Global___FieldOptions: typing_extensions.TypeAlias = FieldOptions 45 | 46 | OPTIONS_FIELD_NUMBER: builtins.int 47 | CASTTYPE_FIELD_NUMBER: builtins.int 48 | KEYTYPE_FIELD_NUMBER: builtins.int 49 | VALUETYPE_FIELD_NUMBER: builtins.int 50 | options: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, Global___FieldOptions] 51 | """Custom field options from mypy-protobuf""" 52 | casttype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 53 | """Legacy fields. Prefer to use ones within `options` instead.""" 54 | keytype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 55 | valuetype: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 56 | -------------------------------------------------------------------------------- /test/generated/testproto/test_extensions3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.extension_dict 11 | import google.protobuf.message 12 | import sys 13 | import testproto.test3_pb2 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | @typing.final 24 | class MessageOptionsTestMsg(google.protobuf.message.Message): 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___MessageOptionsTestMsg: typing_extensions.TypeAlias = MessageOptionsTestMsg 32 | 33 | TEST_FIELD_EXTENSION_FIELD_NUMBER: builtins.int 34 | SCALAR_OPTION_FIELD_NUMBER: builtins.int 35 | REPEATED_SCALAR_OPTION_FIELD_NUMBER: builtins.int 36 | ENUM_OPTION_FIELD_NUMBER: builtins.int 37 | REPEATED_ENUM_OPTION_FIELD_NUMBER: builtins.int 38 | MSG_OPTION_FIELD_NUMBER: builtins.int 39 | REPEATED_MSG_OPTION_FIELD_NUMBER: builtins.int 40 | test_field_extension: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 41 | scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, builtins.str] 42 | repeated_scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]] 43 | enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterEnum.ValueType] 44 | repeated_enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[testproto.test3_pb2.OuterEnum.ValueType]] 45 | msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterMessage3] 46 | repeated_msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedCompositeFieldContainer[testproto.test3_pb2.OuterMessage3]] 47 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/test_extensions3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.extension_dict 11 | import google.protobuf.message 12 | import sys 13 | import testproto.test3_pb2 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | @typing.final 24 | class MessageOptionsTestMsg(google.protobuf.message.Message): 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___MessageOptionsTestMsg: typing_extensions.TypeAlias = MessageOptionsTestMsg 32 | 33 | TEST_FIELD_EXTENSION_FIELD_NUMBER: builtins.int 34 | SCALAR_OPTION_FIELD_NUMBER: builtins.int 35 | REPEATED_SCALAR_OPTION_FIELD_NUMBER: builtins.int 36 | ENUM_OPTION_FIELD_NUMBER: builtins.int 37 | REPEATED_ENUM_OPTION_FIELD_NUMBER: builtins.int 38 | MSG_OPTION_FIELD_NUMBER: builtins.int 39 | REPEATED_MSG_OPTION_FIELD_NUMBER: builtins.int 40 | test_field_extension: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 41 | scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, builtins.str] 42 | repeated_scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]] 43 | enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterEnum.ValueType] 44 | repeated_enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[testproto.test3_pb2.OuterEnum.ValueType]] 45 | msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterMessage3] 46 | repeated_msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedCompositeFieldContainer[testproto.test3_pb2.OuterMessage3]] 47 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/test_extensions3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.extension_dict 11 | import google.protobuf.message 12 | import sys 13 | import testproto.test3_pb2 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | @typing.final 24 | class MessageOptionsTestMsg(google.protobuf.message.Message): 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___MessageOptionsTestMsg: typing_extensions.TypeAlias = MessageOptionsTestMsg 32 | 33 | TEST_FIELD_EXTENSION_FIELD_NUMBER: builtins.int 34 | SCALAR_OPTION_FIELD_NUMBER: builtins.int 35 | REPEATED_SCALAR_OPTION_FIELD_NUMBER: builtins.int 36 | ENUM_OPTION_FIELD_NUMBER: builtins.int 37 | REPEATED_ENUM_OPTION_FIELD_NUMBER: builtins.int 38 | MSG_OPTION_FIELD_NUMBER: builtins.int 39 | REPEATED_MSG_OPTION_FIELD_NUMBER: builtins.int 40 | test_field_extension: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 41 | scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, builtins.str] 42 | repeated_scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]] 43 | enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterEnum.ValueType] 44 | repeated_enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[testproto.test3_pb2.OuterEnum.ValueType]] 45 | msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterMessage3] 46 | repeated_msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedCompositeFieldContainer[testproto.test3_pb2.OuterMessage3]] 47 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test_extensions3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.descriptor_pb2 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.extension_dict 11 | import google.protobuf.message 12 | import sys 13 | import testproto.test3_pb2 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | @typing.final 24 | class MessageOptionsTestMsg(google.protobuf.message.Message): 25 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 26 | 27 | def __init__( 28 | self, 29 | ) -> None: ... 30 | 31 | Global___MessageOptionsTestMsg: typing_extensions.TypeAlias = MessageOptionsTestMsg 32 | 33 | TEST_FIELD_EXTENSION_FIELD_NUMBER: builtins.int 34 | SCALAR_OPTION_FIELD_NUMBER: builtins.int 35 | REPEATED_SCALAR_OPTION_FIELD_NUMBER: builtins.int 36 | ENUM_OPTION_FIELD_NUMBER: builtins.int 37 | REPEATED_ENUM_OPTION_FIELD_NUMBER: builtins.int 38 | MSG_OPTION_FIELD_NUMBER: builtins.int 39 | REPEATED_MSG_OPTION_FIELD_NUMBER: builtins.int 40 | test_field_extension: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.FieldOptions, builtins.str] 41 | scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, builtins.str] 42 | repeated_scalar_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]] 43 | enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterEnum.ValueType] 44 | repeated_enum_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedScalarFieldContainer[testproto.test3_pb2.OuterEnum.ValueType]] 45 | msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, testproto.test3_pb2.OuterMessage3] 46 | repeated_msg_option: google.protobuf.internal.extension_dict._ExtensionFieldDescriptor[google.protobuf.descriptor_pb2.MessageOptions, google.protobuf.internal.containers.RepeatedCompositeFieldContainer[testproto.test3_pb2.OuterMessage3]] 47 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/grpc/import_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import google.protobuf.empty_pb2 9 | import grpc 10 | import grpc.aio 11 | import testproto.test_pb2 12 | import typing 13 | 14 | _T = typing.TypeVar("_T") 15 | 16 | class _MaybeAsyncIterator(collections.abc.AsyncIterator[_T], collections.abc.Iterator[_T], metaclass=abc.ABCMeta): ... 17 | 18 | class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ignore[misc, type-arg] 19 | ... 20 | 21 | GRPC_GENERATED_VERSION: str 22 | GRPC_VERSION: str 23 | 24 | class SimpleServiceStub: 25 | """SimpleService""" 26 | 27 | @typing.overload 28 | def __new__(cls, channel: grpc.Channel) -> SimpleServiceStub: ... 29 | @typing.overload 30 | def __new__(cls, channel: grpc.aio.Channel) -> SimpleServiceAsyncStub: ... 31 | UnaryUnary: grpc.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] 32 | """UnaryUnary""" 33 | UnaryStream: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 34 | """UnaryStream""" 35 | NoComment: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 36 | 37 | @typing.type_check_only 38 | class SimpleServiceAsyncStub(SimpleServiceStub): 39 | """SimpleService""" 40 | 41 | def __init__(self, channel: grpc.aio.Channel) -> None: ... 42 | UnaryUnary: grpc.aio.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] # type: ignore[assignment] 43 | """UnaryUnary""" 44 | UnaryStream: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] # type: ignore[assignment] 45 | """UnaryStream""" 46 | NoComment: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] # type: ignore[assignment] 47 | 48 | class SimpleServiceServicer: 49 | """SimpleService""" 50 | 51 | def UnaryUnary( 52 | self, 53 | request: google.protobuf.empty_pb2.Empty, 54 | context: _ServicerContext, 55 | ) -> typing.Union[testproto.test_pb2.Simple1, collections.abc.Awaitable[testproto.test_pb2.Simple1]]: 56 | """UnaryUnary""" 57 | 58 | def UnaryStream( 59 | self, 60 | request: testproto.test_pb2.Simple1, 61 | context: _ServicerContext, 62 | ) -> typing.Union[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]]: 63 | """UnaryStream""" 64 | 65 | def NoComment( 66 | self, 67 | request: testproto.test_pb2.Simple1, 68 | context: _ServicerContext, 69 | ) -> typing.Union[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]]: ... 70 | 71 | def add_SimpleServiceServicer_to_server(servicer: SimpleServiceServicer, server: typing.Union[grpc.Server, grpc.aio.Server]) -> None: ... 72 | -------------------------------------------------------------------------------- /test/generated/testproto/comment_special_chars_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Test(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | B_FIELD_NUMBER: builtins.int 25 | C_FIELD_NUMBER: builtins.int 26 | D_FIELD_NUMBER: builtins.int 27 | E_FIELD_NUMBER: builtins.int 28 | F_FIELD_NUMBER: builtins.int 29 | G_FIELD_NUMBER: builtins.int 30 | H_FIELD_NUMBER: builtins.int 31 | I_FIELD_NUMBER: builtins.int 32 | J_FIELD_NUMBER: builtins.int 33 | K_FIELD_NUMBER: builtins.int 34 | a: builtins.str 35 | """Ending with " """ 36 | b: builtins.str 37 | """Ending with "" """ 38 | c: builtins.str 39 | """Ending with \"\"\" """ 40 | d: builtins.str 41 | """Ending with \\ """ 42 | e: builtins.str 43 | """Containing bad escape: \\x""" 44 | f: builtins.str 45 | """Containing \"\"\"" quadruple""" 46 | g: builtins.str 47 | """Containing \"\"\""" quintuple""" 48 | h: builtins.str 49 | """Containing \"\"\"\"\"\" sextuple""" 50 | i: builtins.str 51 | """\"\"\" Multiple \"\"\" triples \"\"\" """ 52 | j: builtins.str 53 | """"quotes" can be a problem in comments. 54 | \"\"\"Triple quotes\"\"\" just as well 55 | """ 56 | k: builtins.str 57 | """\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 58 | " " 59 | " Super Duper comments with surrounding edges! " 60 | " " 61 | " Pay attention to me!!!! " 62 | " " 63 | \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 64 | """ 65 | def __init__( 66 | self, 67 | *, 68 | a: builtins.str = ..., 69 | b: builtins.str = ..., 70 | c: builtins.str = ..., 71 | d: builtins.str = ..., 72 | e: builtins.str = ..., 73 | f: builtins.str = ..., 74 | g: builtins.str = ..., 75 | h: builtins.str = ..., 76 | i: builtins.str = ..., 77 | j: builtins.str = ..., 78 | k: builtins.str = ..., 79 | ) -> None: ... 80 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a", "b", b"b", "c", b"c", "d", b"d", "e", b"e", "f", b"f", "g", b"g", "h", b"h", "i", b"i", "j", b"j", "k", b"k"] 81 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 82 | 83 | Global___Test: typing_extensions.TypeAlias = Test 84 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/comment_special_chars_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Test(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | B_FIELD_NUMBER: builtins.int 25 | C_FIELD_NUMBER: builtins.int 26 | D_FIELD_NUMBER: builtins.int 27 | E_FIELD_NUMBER: builtins.int 28 | F_FIELD_NUMBER: builtins.int 29 | G_FIELD_NUMBER: builtins.int 30 | H_FIELD_NUMBER: builtins.int 31 | I_FIELD_NUMBER: builtins.int 32 | J_FIELD_NUMBER: builtins.int 33 | K_FIELD_NUMBER: builtins.int 34 | a: builtins.str 35 | """Ending with " """ 36 | b: builtins.str 37 | """Ending with "" """ 38 | c: builtins.str 39 | """Ending with \"\"\" """ 40 | d: builtins.str 41 | """Ending with \\ """ 42 | e: builtins.str 43 | """Containing bad escape: \\x""" 44 | f: builtins.str 45 | """Containing \"\"\"" quadruple""" 46 | g: builtins.str 47 | """Containing \"\"\""" quintuple""" 48 | h: builtins.str 49 | """Containing \"\"\"\"\"\" sextuple""" 50 | i: builtins.str 51 | """\"\"\" Multiple \"\"\" triples \"\"\" """ 52 | j: builtins.str 53 | """"quotes" can be a problem in comments. 54 | \"\"\"Triple quotes\"\"\" just as well 55 | """ 56 | k: builtins.str 57 | """\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 58 | " " 59 | " Super Duper comments with surrounding edges! " 60 | " " 61 | " Pay attention to me!!!! " 62 | " " 63 | \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 64 | """ 65 | def __init__( 66 | self, 67 | *, 68 | a: builtins.str = ..., 69 | b: builtins.str = ..., 70 | c: builtins.str = ..., 71 | d: builtins.str = ..., 72 | e: builtins.str = ..., 73 | f: builtins.str = ..., 74 | g: builtins.str = ..., 75 | h: builtins.str = ..., 76 | i: builtins.str = ..., 77 | j: builtins.str = ..., 78 | k: builtins.str = ..., 79 | ) -> None: ... 80 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a", "b", b"b", "c", b"c", "d", b"d", "e", b"e", "f", b"f", "g", b"g", "h", b"h", "i", b"i", "j", b"j", "k", b"k"] 81 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 82 | 83 | Global___Test: typing_extensions.TypeAlias = Test 84 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/comment_special_chars_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Test(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | B_FIELD_NUMBER: builtins.int 25 | C_FIELD_NUMBER: builtins.int 26 | D_FIELD_NUMBER: builtins.int 27 | E_FIELD_NUMBER: builtins.int 28 | F_FIELD_NUMBER: builtins.int 29 | G_FIELD_NUMBER: builtins.int 30 | H_FIELD_NUMBER: builtins.int 31 | I_FIELD_NUMBER: builtins.int 32 | J_FIELD_NUMBER: builtins.int 33 | K_FIELD_NUMBER: builtins.int 34 | a: builtins.str 35 | """Ending with " """ 36 | b: builtins.str 37 | """Ending with "" """ 38 | c: builtins.str 39 | """Ending with \"\"\" """ 40 | d: builtins.str 41 | """Ending with \\ """ 42 | e: builtins.str 43 | """Containing bad escape: \\x""" 44 | f: builtins.str 45 | """Containing \"\"\"" quadruple""" 46 | g: builtins.str 47 | """Containing \"\"\""" quintuple""" 48 | h: builtins.str 49 | """Containing \"\"\"\"\"\" sextuple""" 50 | i: builtins.str 51 | """\"\"\" Multiple \"\"\" triples \"\"\" """ 52 | j: builtins.str 53 | """"quotes" can be a problem in comments. 54 | \"\"\"Triple quotes\"\"\" just as well 55 | """ 56 | k: builtins.str 57 | """\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 58 | " " 59 | " Super Duper comments with surrounding edges! " 60 | " " 61 | " Pay attention to me!!!! " 62 | " " 63 | \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 64 | """ 65 | def __init__( 66 | self, 67 | *, 68 | a: builtins.str = ..., 69 | b: builtins.str = ..., 70 | c: builtins.str = ..., 71 | d: builtins.str = ..., 72 | e: builtins.str = ..., 73 | f: builtins.str = ..., 74 | g: builtins.str = ..., 75 | h: builtins.str = ..., 76 | i: builtins.str = ..., 77 | j: builtins.str = ..., 78 | k: builtins.str = ..., 79 | ) -> None: ... 80 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a", "b", b"b", "c", b"c", "d", b"d", "e", b"e", "f", b"f", "g", b"g", "h", b"h", "i", b"i", "j", b"j", "k", b"k"] 81 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 82 | 83 | Global___Test: typing_extensions.TypeAlias = Test 84 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/comment_special_chars_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Test(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | A_FIELD_NUMBER: builtins.int 24 | B_FIELD_NUMBER: builtins.int 25 | C_FIELD_NUMBER: builtins.int 26 | D_FIELD_NUMBER: builtins.int 27 | E_FIELD_NUMBER: builtins.int 28 | F_FIELD_NUMBER: builtins.int 29 | G_FIELD_NUMBER: builtins.int 30 | H_FIELD_NUMBER: builtins.int 31 | I_FIELD_NUMBER: builtins.int 32 | J_FIELD_NUMBER: builtins.int 33 | K_FIELD_NUMBER: builtins.int 34 | a: builtins.str 35 | """Ending with " """ 36 | b: builtins.str 37 | """Ending with "" """ 38 | c: builtins.str 39 | """Ending with \"\"\" """ 40 | d: builtins.str 41 | """Ending with \\ """ 42 | e: builtins.str 43 | """Containing bad escape: \\x""" 44 | f: builtins.str 45 | """Containing \"\"\"" quadruple""" 46 | g: builtins.str 47 | """Containing \"\"\""" quintuple""" 48 | h: builtins.str 49 | """Containing \"\"\"\"\"\" sextuple""" 50 | i: builtins.str 51 | """\"\"\" Multiple \"\"\" triples \"\"\" """ 52 | j: builtins.str 53 | """"quotes" can be a problem in comments. 54 | \"\"\"Triple quotes\"\"\" just as well 55 | """ 56 | k: builtins.str 57 | """\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 58 | " " 59 | " Super Duper comments with surrounding edges! " 60 | " " 61 | " Pay attention to me!!!! " 62 | " " 63 | \"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" 64 | """ 65 | def __init__( 66 | self, 67 | *, 68 | a: builtins.str = ..., 69 | b: builtins.str = ..., 70 | c: builtins.str = ..., 71 | d: builtins.str = ..., 72 | e: builtins.str = ..., 73 | f: builtins.str = ..., 74 | g: builtins.str = ..., 75 | h: builtins.str = ..., 76 | i: builtins.str = ..., 77 | j: builtins.str = ..., 78 | k: builtins.str = ..., 79 | ) -> None: ... 80 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a", "b", b"b", "c", b"c", "d", b"d", "e", b"e", "f", b"f", "g", b"g", "h", b"h", "i", b"i", "j", b"j", "k", b"k"] 81 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 82 | 83 | Global___Test: typing_extensions.TypeAlias = Test 84 | -------------------------------------------------------------------------------- /test/generated/testproto/grpc/import_pb2_grpc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import abc 7 | import collections.abc 8 | import google.protobuf.empty_pb2 9 | import grpc 10 | import grpc.aio 11 | import testproto.test_pb2 12 | import typing 13 | 14 | _T = typing.TypeVar("_T") 15 | 16 | class _MaybeAsyncIterator(collections.abc.AsyncIterator[_T], collections.abc.Iterator[_T], metaclass=abc.ABCMeta): ... 17 | 18 | class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ignore[misc, type-arg] 19 | ... 20 | 21 | GRPC_GENERATED_VERSION: str 22 | GRPC_VERSION: str 23 | 24 | class SimpleServiceStub: 25 | """SimpleService""" 26 | 27 | @typing.overload 28 | def __new__(cls, channel: grpc.Channel) -> SimpleServiceStub: ... 29 | @typing.overload 30 | def __new__(cls, channel: grpc.aio.Channel) -> SimpleServiceAsyncStub: ... 31 | UnaryUnary: grpc.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] 32 | """UnaryUnary""" 33 | UnaryStream: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 34 | """UnaryStream""" 35 | NoComment: grpc.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] 36 | 37 | @typing.type_check_only 38 | class SimpleServiceAsyncStub(SimpleServiceStub): 39 | """SimpleService""" 40 | 41 | def __init__(self, channel: grpc.aio.Channel) -> None: ... 42 | UnaryUnary: grpc.aio.UnaryUnaryMultiCallable[google.protobuf.empty_pb2.Empty, testproto.test_pb2.Simple1] # type: ignore[assignment] 43 | """UnaryUnary""" 44 | UnaryStream: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] # type: ignore[assignment] 45 | """UnaryStream""" 46 | NoComment: grpc.aio.UnaryUnaryMultiCallable[testproto.test_pb2.Simple1, google.protobuf.empty_pb2.Empty] # type: ignore[assignment] 47 | 48 | class SimpleServiceServicer(metaclass=abc.ABCMeta): 49 | """SimpleService""" 50 | 51 | @abc.abstractmethod 52 | def UnaryUnary( 53 | self, 54 | request: google.protobuf.empty_pb2.Empty, 55 | context: _ServicerContext, 56 | ) -> typing.Union[testproto.test_pb2.Simple1, collections.abc.Awaitable[testproto.test_pb2.Simple1]]: 57 | """UnaryUnary""" 58 | 59 | @abc.abstractmethod 60 | def UnaryStream( 61 | self, 62 | request: testproto.test_pb2.Simple1, 63 | context: _ServicerContext, 64 | ) -> typing.Union[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]]: 65 | """UnaryStream""" 66 | 67 | @abc.abstractmethod 68 | def NoComment( 69 | self, 70 | request: testproto.test_pb2.Simple1, 71 | context: _ServicerContext, 72 | ) -> typing.Union[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]]: ... 73 | 74 | def add_SimpleServiceServicer_to_server(servicer: SimpleServiceServicer, server: typing.Union[grpc.Server, grpc.aio.Server]) -> None: ... 75 | -------------------------------------------------------------------------------- /test/generated/testproto/edition2024_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Editions2024SubMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | THING_FIELD_NUMBER: builtins.int 24 | thing: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | thing: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Editions2024SubMessage: typing_extensions.TypeAlias = Editions2024SubMessage 36 | 37 | @typing.final 38 | class Editions2024Test(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | LEGACY_FIELD_NUMBER: builtins.int 42 | EXPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 43 | MESSAGE_FIELD_FIELD_NUMBER: builtins.int 44 | IMPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 45 | DEFAULT_SINGULAR_FIELD_NUMBER: builtins.int 46 | legacy: builtins.str 47 | """Expect to be always set""" 48 | explicit_singular: builtins.str 49 | """Expect HasField generated""" 50 | implicit_singular: builtins.str 51 | """Expect implicit field presence, no HasField generated""" 52 | default_singular: builtins.str 53 | """Not set, should default to EXPLICIT""" 54 | @property 55 | def message_field(self) -> Global___Editions2024SubMessage: 56 | """Expect HasField generated?""" 57 | 58 | def __init__( 59 | self, 60 | *, 61 | legacy: builtins.str | None = ..., 62 | explicit_singular: builtins.str | None = ..., 63 | message_field: Global___Editions2024SubMessage | None = ..., 64 | implicit_singular: builtins.str = ..., 65 | default_singular: builtins.str | None = ..., 66 | ) -> None: ... 67 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 68 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 69 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "implicit_singular", b"implicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 70 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 71 | 72 | Global___Editions2024Test: typing_extensions.TypeAlias = Editions2024Test 73 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/edition2024_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Editions2024SubMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | THING_FIELD_NUMBER: builtins.int 24 | thing: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | thing: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Editions2024SubMessage: typing_extensions.TypeAlias = Editions2024SubMessage 36 | 37 | @typing.final 38 | class Editions2024Test(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | LEGACY_FIELD_NUMBER: builtins.int 42 | EXPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 43 | MESSAGE_FIELD_FIELD_NUMBER: builtins.int 44 | IMPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 45 | DEFAULT_SINGULAR_FIELD_NUMBER: builtins.int 46 | legacy: builtins.str 47 | """Expect to be always set""" 48 | explicit_singular: builtins.str 49 | """Expect HasField generated""" 50 | implicit_singular: builtins.str 51 | """Expect implicit field presence, no HasField generated""" 52 | default_singular: builtins.str 53 | """Not set, should default to EXPLICIT""" 54 | @property 55 | def message_field(self) -> Global___Editions2024SubMessage: 56 | """Expect HasField generated?""" 57 | 58 | def __init__( 59 | self, 60 | *, 61 | legacy: builtins.str | None = ..., 62 | explicit_singular: builtins.str | None = ..., 63 | message_field: Global___Editions2024SubMessage | None = ..., 64 | implicit_singular: builtins.str = ..., 65 | default_singular: builtins.str | None = ..., 66 | ) -> None: ... 67 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 68 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 69 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "implicit_singular", b"implicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 70 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 71 | 72 | Global___Editions2024Test: typing_extensions.TypeAlias = Editions2024Test 73 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/edition2024_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Editions2024SubMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | THING_FIELD_NUMBER: builtins.int 24 | thing: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | thing: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Editions2024SubMessage: typing_extensions.TypeAlias = Editions2024SubMessage 36 | 37 | @typing.final 38 | class Editions2024Test(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | LEGACY_FIELD_NUMBER: builtins.int 42 | EXPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 43 | MESSAGE_FIELD_FIELD_NUMBER: builtins.int 44 | IMPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 45 | DEFAULT_SINGULAR_FIELD_NUMBER: builtins.int 46 | legacy: builtins.str 47 | """Expect to be always set""" 48 | explicit_singular: builtins.str 49 | """Expect HasField generated""" 50 | implicit_singular: builtins.str 51 | """Expect implicit field presence, no HasField generated""" 52 | default_singular: builtins.str 53 | """Not set, should default to EXPLICIT""" 54 | @property 55 | def message_field(self) -> Global___Editions2024SubMessage: 56 | """Expect HasField generated?""" 57 | 58 | def __init__( 59 | self, 60 | *, 61 | legacy: builtins.str | None = ..., 62 | explicit_singular: builtins.str | None = ..., 63 | message_field: Global___Editions2024SubMessage | None = ..., 64 | implicit_singular: builtins.str = ..., 65 | default_singular: builtins.str | None = ..., 66 | ) -> None: ... 67 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 68 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 69 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "implicit_singular", b"implicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 70 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 71 | 72 | Global___Editions2024Test: typing_extensions.TypeAlias = Editions2024Test 73 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/edition2024_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Edition version of proto2 file""" 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.message 9 | import sys 10 | import typing 11 | 12 | if sys.version_info >= (3, 10): 13 | import typing as typing_extensions 14 | else: 15 | import typing_extensions 16 | 17 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 18 | 19 | @typing.final 20 | class Editions2024SubMessage(google.protobuf.message.Message): 21 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 22 | 23 | THING_FIELD_NUMBER: builtins.int 24 | thing: builtins.str 25 | def __init__( 26 | self, 27 | *, 28 | thing: builtins.str | None = ..., 29 | ) -> None: ... 30 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 31 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["thing", b"thing"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Editions2024SubMessage: typing_extensions.TypeAlias = Editions2024SubMessage 36 | 37 | @typing.final 38 | class Editions2024Test(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | LEGACY_FIELD_NUMBER: builtins.int 42 | EXPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 43 | MESSAGE_FIELD_FIELD_NUMBER: builtins.int 44 | IMPLICIT_SINGULAR_FIELD_NUMBER: builtins.int 45 | DEFAULT_SINGULAR_FIELD_NUMBER: builtins.int 46 | legacy: builtins.str 47 | """Expect to be always set""" 48 | explicit_singular: builtins.str 49 | """Expect HasField generated""" 50 | implicit_singular: builtins.str 51 | """Expect implicit field presence, no HasField generated""" 52 | default_singular: builtins.str 53 | """Not set, should default to EXPLICIT""" 54 | @property 55 | def message_field(self) -> Global___Editions2024SubMessage: 56 | """Expect HasField generated?""" 57 | 58 | def __init__( 59 | self, 60 | *, 61 | legacy: builtins.str | None = ..., 62 | explicit_singular: builtins.str | None = ..., 63 | message_field: Global___Editions2024SubMessage | None = ..., 64 | implicit_singular: builtins.str = ..., 65 | default_singular: builtins.str | None = ..., 66 | ) -> None: ... 67 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 68 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 69 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["default_singular", b"default_singular", "explicit_singular", b"explicit_singular", "implicit_singular", b"implicit_singular", "legacy", b"legacy", "message_field", b"message_field"] 70 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 71 | 72 | Global___Editions2024Test: typing_extensions.TypeAlias = Editions2024Test 73 | -------------------------------------------------------------------------------- /test/test_grpc_async_usage.py: -------------------------------------------------------------------------------- 1 | import grpc.aio 2 | import pytest 3 | import typing_extensions as typing 4 | from testproto.grpc import dummy_pb2, dummy_pb2_grpc 5 | 6 | ADDRESS = "localhost:22223" 7 | 8 | 9 | class Servicer(dummy_pb2_grpc.DummyServiceServicer): 10 | async def UnaryUnary( 11 | self, 12 | request: dummy_pb2.DummyRequest, 13 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, dummy_pb2.DummyReply], 14 | ) -> dummy_pb2.DummyReply: 15 | return dummy_pb2.DummyReply(value=request.value[::-1]) 16 | 17 | async def UnaryStream( 18 | self, 19 | request: dummy_pb2.DummyRequest, 20 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, dummy_pb2.DummyReply], 21 | ) -> typing.AsyncIterator[dummy_pb2.DummyReply]: 22 | for char in request.value: 23 | yield dummy_pb2.DummyReply(value=char) 24 | 25 | async def StreamUnary( 26 | self, 27 | request_iterator: typing.AsyncIterator[dummy_pb2.DummyRequest], 28 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, dummy_pb2.DummyReply], 29 | ) -> dummy_pb2.DummyReply: 30 | values = [data.value async for data in request_iterator] 31 | return dummy_pb2.DummyReply(value="".join(values)) 32 | 33 | async def StreamStream( 34 | self, 35 | request_iterator: typing.AsyncIterator[dummy_pb2.DummyRequest], 36 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, dummy_pb2.DummyReply], 37 | ) -> typing.AsyncIterator[dummy_pb2.DummyReply]: 38 | async for data in request_iterator: 39 | yield dummy_pb2.DummyReply(value=data.value.upper()) 40 | 41 | 42 | def make_server() -> grpc.aio.Server: 43 | server = grpc.aio.server() 44 | servicer = Servicer() 45 | server.add_insecure_port(ADDRESS) 46 | dummy_pb2_grpc.add_DummyServiceServicer_to_server(servicer, server) 47 | return server 48 | 49 | 50 | @pytest.mark.asyncio 51 | async def test_grpc() -> None: 52 | server = make_server() 53 | await server.start() 54 | async with grpc.aio.insecure_channel(ADDRESS) as channel: 55 | client = dummy_pb2_grpc.DummyServiceStub(channel) 56 | request = dummy_pb2.DummyRequest(value="cprg") 57 | result1 = await client.UnaryUnary(request) 58 | result2 = client.UnaryStream(dummy_pb2.DummyRequest(value=result1.value)) 59 | result2_list = [r async for r in result2] 60 | assert len(result2_list) == 4 61 | result3 = client.StreamStream(dummy_pb2.DummyRequest(value=part.value) for part in result2_list) 62 | result3_list = [r async for r in result3] 63 | assert len(result3_list) == 4 64 | result4 = await client.StreamUnary(dummy_pb2.DummyRequest(value=part.value) for part in result3_list) 65 | assert result4.value == "GRPC" 66 | 67 | await server.stop(None) 68 | 69 | class TestAttribute: 70 | stub: "dummy_pb2_grpc.DummyServiceAsyncStub" 71 | 72 | def __init__(self) -> None: 73 | self.stub = dummy_pb2_grpc.DummyServiceStub(grpc.aio.insecure_channel(ADDRESS)) 74 | 75 | async def test(self) -> None: 76 | val = await self.stub.UnaryUnary(dummy_pb2.DummyRequest(value="test")) 77 | typing.assert_type(val, dummy_pb2.DummyReply) 78 | -------------------------------------------------------------------------------- /test/test_grpc_usage.py: -------------------------------------------------------------------------------- 1 | from concurrent import futures 2 | 3 | import grpc 4 | import typing_extensions as typing 5 | from testproto.grpc import dummy_pb2, dummy_pb2_grpc 6 | 7 | ADDRESS = "localhost:22222" 8 | 9 | 10 | class Servicer(dummy_pb2_grpc.DummyServiceServicer): 11 | def UnaryUnary( 12 | self, 13 | request: dummy_pb2.DummyRequest, 14 | context: grpc.ServicerContext, 15 | ) -> dummy_pb2.DummyReply: 16 | return dummy_pb2.DummyReply(value=request.value[::-1]) 17 | 18 | def UnaryStream( 19 | self, 20 | request: dummy_pb2.DummyRequest, 21 | context: grpc.ServicerContext, 22 | ) -> typing.Iterator[dummy_pb2.DummyReply]: 23 | for char in request.value: 24 | yield dummy_pb2.DummyReply(value=char) 25 | 26 | def StreamUnary( 27 | self, 28 | request_iterator: typing.Iterator[dummy_pb2.DummyRequest], 29 | context: grpc.ServicerContext, 30 | ) -> dummy_pb2.DummyReply: 31 | return dummy_pb2.DummyReply(value="".join(data.value for data in request_iterator)) 32 | 33 | def StreamStream( 34 | self, 35 | request_iterator: typing.Iterator[dummy_pb2.DummyRequest], 36 | context: grpc.ServicerContext, 37 | ) -> typing.Iterator[dummy_pb2.DummyReply]: 38 | for data in request_iterator: 39 | yield dummy_pb2.DummyReply(value=data.value.upper()) 40 | 41 | 42 | def make_server() -> grpc.Server: 43 | server = grpc.server(futures.ThreadPoolExecutor()) 44 | servicer = Servicer() 45 | server.add_insecure_port(ADDRESS) 46 | dummy_pb2_grpc.add_DummyServiceServicer_to_server(servicer, server) 47 | return server 48 | 49 | 50 | def test_grpc() -> None: 51 | server = make_server() 52 | server.start() 53 | channel = grpc.insecure_channel(ADDRESS) 54 | client = dummy_pb2_grpc.DummyServiceStub(channel) 55 | request = dummy_pb2.DummyRequest(value="cprg") 56 | result1 = client.UnaryUnary(request) 57 | result2 = client.UnaryStream(dummy_pb2.DummyRequest(value=result1.value)) 58 | result2_list = list(result2) 59 | assert len(result2_list) == 4 60 | result3 = client.StreamStream(dummy_pb2.DummyRequest(value=part.value) for part in result2_list) 61 | result3_list = list(result3) 62 | assert len(result3_list) == 4 63 | result4 = client.StreamUnary(dummy_pb2.DummyRequest(value=part.value) for part in result3_list) 64 | assert result4.value == "GRPC" 65 | 66 | # test future() in MultiCallable 67 | future_test: grpc._CallFuture[dummy_pb2.DummyReply] = client.UnaryUnary.future(request) 68 | result5 = future_test.result() 69 | print(result5) 70 | assert result5.value == "grpc" 71 | 72 | # test params on __call__ in MultiCallable 73 | result6: dummy_pb2.DummyReply = client.UnaryUnary(request, timeout=4, metadata=(("test", "metadata"), ("cheems", "many"))) 74 | 75 | assert result6.value == "grpc" 76 | 77 | server.stop(None) 78 | 79 | class TestAttribute: 80 | stub: dummy_pb2_grpc.DummyServiceStub 81 | 82 | def __init__(self) -> None: 83 | self.stub = dummy_pb2_grpc.DummyServiceStub(grpc.insecure_channel(ADDRESS)) 84 | 85 | def test(self) -> None: 86 | val = self.stub.UnaryUnary(dummy_pb2.DummyRequest(value="test")) 87 | typing.assert_type(val, dummy_pb2.DummyReply) 88 | -------------------------------------------------------------------------------- /test/sync_only/test_sync_only.py: -------------------------------------------------------------------------------- 1 | """ 2 | Type-checking and runtime test for sync_only GRPC stubs. 3 | 4 | This module validates that stubs generated with the only_sync flag have the correct types: 5 | - Regular (non-generic) Stub class that only accepts grpc.Channel 6 | - Servicer methods use Iterator for client streaming (not _MaybeAsyncIterator) 7 | - add_XXXServicer_to_server accepts grpc.Server 8 | """ 9 | 10 | from concurrent import futures 11 | 12 | import grpc 13 | import typing_extensions as typing 14 | from testproto.grpc import dummy_pb2, dummy_pb2_grpc 15 | 16 | ADDRESS = "localhost:22224" 17 | 18 | 19 | class Servicer(dummy_pb2_grpc.DummyServiceServicer): 20 | def UnaryUnary( 21 | self, 22 | request: dummy_pb2.DummyRequest, 23 | context: grpc.ServicerContext, 24 | ) -> dummy_pb2.DummyReply: 25 | return dummy_pb2.DummyReply(value=request.value[::-1]) 26 | 27 | def UnaryStream( 28 | self, 29 | request: dummy_pb2.DummyRequest, 30 | context: grpc.ServicerContext, 31 | ) -> typing.Iterator[dummy_pb2.DummyReply]: 32 | for char in request.value: 33 | yield dummy_pb2.DummyReply(value=char) 34 | 35 | def StreamUnary( 36 | self, 37 | request_iterator: typing.Iterator[dummy_pb2.DummyRequest], 38 | context: grpc.ServicerContext, 39 | ) -> dummy_pb2.DummyReply: 40 | return dummy_pb2.DummyReply(value="".join(data.value for data in request_iterator)) 41 | 42 | def StreamStream( 43 | self, 44 | request_iterator: typing.Iterator[dummy_pb2.DummyRequest], 45 | context: grpc.ServicerContext, 46 | ) -> typing.Iterator[dummy_pb2.DummyReply]: 47 | for data in request_iterator: 48 | yield dummy_pb2.DummyReply(value=data.value.upper()) 49 | 50 | 51 | def make_server() -> grpc.Server: 52 | server = grpc.server(futures.ThreadPoolExecutor()) 53 | servicer = Servicer() 54 | server.add_insecure_port(ADDRESS) 55 | dummy_pb2_grpc.add_DummyServiceServicer_to_server(servicer, server) 56 | return server 57 | 58 | 59 | def test_sync_only_grpc() -> None: 60 | server = make_server() 61 | server.start() 62 | channel = grpc.insecure_channel(ADDRESS) 63 | client = dummy_pb2_grpc.DummyServiceStub(channel) 64 | request = dummy_pb2.DummyRequest(value="cprg") 65 | result1 = client.UnaryUnary(request) 66 | result2 = client.UnaryStream(dummy_pb2.DummyRequest(value=result1.value)) 67 | result2_list = list(result2) 68 | assert len(result2_list) == 4 69 | result3 = client.StreamStream(dummy_pb2.DummyRequest(value=part.value) for part in result2_list) 70 | result3_list = list(result3) 71 | assert len(result3_list) == 4 72 | result4 = client.StreamUnary(dummy_pb2.DummyRequest(value=part.value) for part in result3_list) 73 | assert result4.value == "GRPC" 74 | 75 | # test future() in MultiCallable 76 | future_test: grpc._CallFuture[dummy_pb2.DummyReply] = client.UnaryUnary.future(request) 77 | result5 = future_test.result() 78 | assert result5.value == "grpc" 79 | 80 | # test params on __call__ in MultiCallable 81 | result6: dummy_pb2.DummyReply = client.UnaryUnary(request, timeout=4, metadata=(("test", "metadata"), ("cheems", "many"))) 82 | assert result6.value == "grpc" 83 | 84 | server.stop(None) 85 | 86 | class TestAttribute: 87 | stub: dummy_pb2_grpc.DummyServiceStub 88 | 89 | def __init__(self) -> None: 90 | self.stub = dummy_pb2_grpc.DummyServiceStub(grpc.insecure_channel(ADDRESS)) 91 | 92 | def test(self) -> None: 93 | val = self.stub.UnaryUnary(dummy_pb2.DummyRequest(value="test")) 94 | typing.assert_type(val, dummy_pb2.DummyReply) 95 | -------------------------------------------------------------------------------- /test/async_only/test_async_only.py: -------------------------------------------------------------------------------- 1 | """ 2 | Type-checking and runtime test for async_only GRPC stubs. 3 | 4 | This module validates that stubs generated with the only_async flag have the correct types: 5 | - Stub class (not AsyncStub) that only accepts grpc.aio.Channel 6 | - Servicer methods use AsyncIterator for client streaming (not _MaybeAsyncIterator) 7 | - add_XXXServicer_to_server accepts grpc.aio.Server 8 | """ 9 | 10 | import grpc.aio 11 | import pytest 12 | import typing_extensions as typing 13 | from testproto.grpc import dummy_pb2, dummy_pb2_grpc 14 | 15 | ADDRESS = "localhost:22225" 16 | 17 | 18 | class Servicer(dummy_pb2_grpc.DummyServiceServicer): 19 | async def UnaryUnary( 20 | self, 21 | request: dummy_pb2.DummyRequest, 22 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, typing.Awaitable[dummy_pb2.DummyReply]], 23 | ) -> dummy_pb2.DummyReply: 24 | return dummy_pb2.DummyReply(value=request.value[::-1]) 25 | 26 | async def UnaryStream( 27 | self, 28 | request: dummy_pb2.DummyRequest, 29 | context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, typing.AsyncIterator[dummy_pb2.DummyReply]], 30 | ) -> typing.AsyncIterator[dummy_pb2.DummyReply]: 31 | for char in request.value: 32 | yield dummy_pb2.DummyReply(value=char) 33 | 34 | async def StreamUnary( 35 | self, 36 | request_iterator: typing.AsyncIterator[dummy_pb2.DummyRequest], 37 | context: grpc.aio.ServicerContext[typing.AsyncIterator[dummy_pb2.DummyRequest], typing.Awaitable[dummy_pb2.DummyReply]], 38 | ) -> dummy_pb2.DummyReply: 39 | values = [data.value async for data in request_iterator] 40 | return dummy_pb2.DummyReply(value="".join(values)) 41 | 42 | async def StreamStream( 43 | self, 44 | request_iterator: typing.AsyncIterator[dummy_pb2.DummyRequest], 45 | context: grpc.aio.ServicerContext[typing.AsyncIterator[dummy_pb2.DummyRequest], typing.AsyncIterator[dummy_pb2.DummyReply]], 46 | ) -> typing.AsyncIterator[dummy_pb2.DummyReply]: 47 | async for data in request_iterator: 48 | yield dummy_pb2.DummyReply(value=data.value.upper()) 49 | 50 | 51 | def make_server() -> grpc.aio.Server: 52 | server = grpc.aio.server() 53 | servicer = Servicer() 54 | server.add_insecure_port(ADDRESS) 55 | dummy_pb2_grpc.add_DummyServiceServicer_to_server(servicer, server) 56 | return server 57 | 58 | 59 | @pytest.mark.asyncio 60 | async def test_async_only_grpc() -> None: 61 | server = make_server() 62 | await server.start() 63 | async with grpc.aio.insecure_channel(ADDRESS) as channel: 64 | client = dummy_pb2_grpc.DummyServiceStub(channel) 65 | request = dummy_pb2.DummyRequest(value="cprg") 66 | result1 = await client.UnaryUnary(request) 67 | result2 = client.UnaryStream(dummy_pb2.DummyRequest(value=result1.value)) 68 | result2_list = [r async for r in result2] 69 | assert len(result2_list) == 4 70 | result3 = client.StreamStream(dummy_pb2.DummyRequest(value=part.value) for part in result2_list) 71 | result3_list = [r async for r in result3] 72 | assert len(result3_list) == 4 73 | result4 = await client.StreamUnary(dummy_pb2.DummyRequest(value=part.value) for part in result3_list) 74 | assert result4.value == "GRPC" 75 | 76 | await server.stop(None) 77 | 78 | class TestAttribute: 79 | stub: "dummy_pb2_grpc.DummyServiceStub" 80 | 81 | def __init__(self) -> None: 82 | self.stub = dummy_pb2_grpc.DummyServiceStub(grpc.aio.insecure_channel(ADDRESS)) 83 | 84 | async def test(self) -> None: 85 | val = await self.stub.UnaryUnary(dummy_pb2.DummyRequest(value="test")) 86 | typing.assert_type(val, dummy_pb2.DummyReply) 87 | -------------------------------------------------------------------------------- /test/generated/testproto/nested/nested_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test3_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class Nested(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | A_FIELD_NUMBER: builtins.int 26 | a: testproto.test3_pb2.OuterEnum.ValueType 27 | def __init__( 28 | self, 29 | *, 30 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 31 | ) -> None: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Nested: typing_extensions.TypeAlias = Nested 36 | 37 | @typing.final 38 | class AnotherNested(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | class _NestedEnum: 42 | ValueType = typing.NewType("ValueType", builtins.int) 43 | V: typing_extensions.TypeAlias = ValueType 44 | 45 | class _NestedEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested._NestedEnum.ValueType], builtins.type): 46 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 47 | INVALID: AnotherNested._NestedEnum.ValueType # 0 48 | ONE: AnotherNested._NestedEnum.ValueType # 1 49 | TWO: AnotherNested._NestedEnum.ValueType # 2 50 | 51 | class NestedEnum(_NestedEnum, metaclass=_NestedEnumEnumTypeWrapper): ... 52 | INVALID: AnotherNested.NestedEnum.ValueType # 0 53 | ONE: AnotherNested.NestedEnum.ValueType # 1 54 | TWO: AnotherNested.NestedEnum.ValueType # 2 55 | 56 | @typing.final 57 | class NestedMessage(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _NestedEnum2: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _NestedEnum2EnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested.NestedMessage._NestedEnum2.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | UNDEFINED: AnotherNested.NestedMessage._NestedEnum2.ValueType # 0 67 | NESTED_ENUM1: AnotherNested.NestedMessage._NestedEnum2.ValueType # 1 68 | NESTED_ENUM2: AnotherNested.NestedMessage._NestedEnum2.ValueType # 2 69 | 70 | class NestedEnum2(_NestedEnum2, metaclass=_NestedEnum2EnumTypeWrapper): ... 71 | UNDEFINED: AnotherNested.NestedMessage.NestedEnum2.ValueType # 0 72 | NESTED_ENUM1: AnotherNested.NestedMessage.NestedEnum2.ValueType # 1 73 | NESTED_ENUM2: AnotherNested.NestedMessage.NestedEnum2.ValueType # 2 74 | 75 | S_FIELD_NUMBER: builtins.int 76 | B_FIELD_NUMBER: builtins.int 77 | NE_FIELD_NUMBER: builtins.int 78 | NE2_FIELD_NUMBER: builtins.int 79 | s: builtins.str 80 | b: builtins.bool 81 | ne: Global___AnotherNested.NestedEnum.ValueType 82 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType 83 | def __init__( 84 | self, 85 | *, 86 | s: builtins.str = ..., 87 | b: builtins.bool = ..., 88 | ne: Global___AnotherNested.NestedEnum.ValueType = ..., 89 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType = ..., 90 | ) -> None: ... 91 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["b", b"b", "ne", b"ne", "ne2", b"ne2", "s", b"s"] 92 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 93 | 94 | def __init__( 95 | self, 96 | ) -> None: ... 97 | 98 | Global___AnotherNested: typing_extensions.TypeAlias = AnotherNested 99 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/nested/nested_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test3_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class Nested(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | A_FIELD_NUMBER: builtins.int 26 | a: testproto.test3_pb2.OuterEnum.ValueType 27 | def __init__( 28 | self, 29 | *, 30 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 31 | ) -> None: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Nested: typing_extensions.TypeAlias = Nested 36 | 37 | @typing.final 38 | class AnotherNested(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | class _NestedEnum: 42 | ValueType = typing.NewType("ValueType", builtins.int) 43 | V: typing_extensions.TypeAlias = ValueType 44 | 45 | class _NestedEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested._NestedEnum.ValueType], builtins.type): 46 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 47 | INVALID: AnotherNested._NestedEnum.ValueType # 0 48 | ONE: AnotherNested._NestedEnum.ValueType # 1 49 | TWO: AnotherNested._NestedEnum.ValueType # 2 50 | 51 | class NestedEnum(_NestedEnum, metaclass=_NestedEnumEnumTypeWrapper): ... 52 | INVALID: AnotherNested.NestedEnum.ValueType # 0 53 | ONE: AnotherNested.NestedEnum.ValueType # 1 54 | TWO: AnotherNested.NestedEnum.ValueType # 2 55 | 56 | @typing.final 57 | class NestedMessage(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _NestedEnum2: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _NestedEnum2EnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested.NestedMessage._NestedEnum2.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | UNDEFINED: AnotherNested.NestedMessage._NestedEnum2.ValueType # 0 67 | NESTED_ENUM1: AnotherNested.NestedMessage._NestedEnum2.ValueType # 1 68 | NESTED_ENUM2: AnotherNested.NestedMessage._NestedEnum2.ValueType # 2 69 | 70 | class NestedEnum2(_NestedEnum2, metaclass=_NestedEnum2EnumTypeWrapper): ... 71 | UNDEFINED: AnotherNested.NestedMessage.NestedEnum2.ValueType # 0 72 | NESTED_ENUM1: AnotherNested.NestedMessage.NestedEnum2.ValueType # 1 73 | NESTED_ENUM2: AnotherNested.NestedMessage.NestedEnum2.ValueType # 2 74 | 75 | S_FIELD_NUMBER: builtins.int 76 | B_FIELD_NUMBER: builtins.int 77 | NE_FIELD_NUMBER: builtins.int 78 | NE2_FIELD_NUMBER: builtins.int 79 | s: builtins.str 80 | b: builtins.bool 81 | ne: Global___AnotherNested.NestedEnum.ValueType 82 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType 83 | def __init__( 84 | self, 85 | *, 86 | s: builtins.str = ..., 87 | b: builtins.bool = ..., 88 | ne: Global___AnotherNested.NestedEnum.ValueType = ..., 89 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType = ..., 90 | ) -> None: ... 91 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["b", b"b", "ne", b"ne", "ne2", b"ne2", "s", b"s"] 92 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 93 | 94 | def __init__( 95 | self, 96 | ) -> None: ... 97 | 98 | Global___AnotherNested: typing_extensions.TypeAlias = AnotherNested 99 | -------------------------------------------------------------------------------- /test/generated_concrete/testproto/nested/nested_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test3_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class Nested(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | A_FIELD_NUMBER: builtins.int 26 | a: testproto.test3_pb2.OuterEnum.ValueType 27 | def __init__( 28 | self, 29 | *, 30 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 31 | ) -> None: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Nested: typing_extensions.TypeAlias = Nested 36 | 37 | @typing.final 38 | class AnotherNested(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | class _NestedEnum: 42 | ValueType = typing.NewType("ValueType", builtins.int) 43 | V: typing_extensions.TypeAlias = ValueType 44 | 45 | class _NestedEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested._NestedEnum.ValueType], builtins.type): 46 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 47 | INVALID: AnotherNested._NestedEnum.ValueType # 0 48 | ONE: AnotherNested._NestedEnum.ValueType # 1 49 | TWO: AnotherNested._NestedEnum.ValueType # 2 50 | 51 | class NestedEnum(_NestedEnum, metaclass=_NestedEnumEnumTypeWrapper): ... 52 | INVALID: AnotherNested.NestedEnum.ValueType # 0 53 | ONE: AnotherNested.NestedEnum.ValueType # 1 54 | TWO: AnotherNested.NestedEnum.ValueType # 2 55 | 56 | @typing.final 57 | class NestedMessage(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _NestedEnum2: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _NestedEnum2EnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested.NestedMessage._NestedEnum2.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | UNDEFINED: AnotherNested.NestedMessage._NestedEnum2.ValueType # 0 67 | NESTED_ENUM1: AnotherNested.NestedMessage._NestedEnum2.ValueType # 1 68 | NESTED_ENUM2: AnotherNested.NestedMessage._NestedEnum2.ValueType # 2 69 | 70 | class NestedEnum2(_NestedEnum2, metaclass=_NestedEnum2EnumTypeWrapper): ... 71 | UNDEFINED: AnotherNested.NestedMessage.NestedEnum2.ValueType # 0 72 | NESTED_ENUM1: AnotherNested.NestedMessage.NestedEnum2.ValueType # 1 73 | NESTED_ENUM2: AnotherNested.NestedMessage.NestedEnum2.ValueType # 2 74 | 75 | S_FIELD_NUMBER: builtins.int 76 | B_FIELD_NUMBER: builtins.int 77 | NE_FIELD_NUMBER: builtins.int 78 | NE2_FIELD_NUMBER: builtins.int 79 | s: builtins.str 80 | b: builtins.bool 81 | ne: Global___AnotherNested.NestedEnum.ValueType 82 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType 83 | def __init__( 84 | self, 85 | *, 86 | s: builtins.str = ..., 87 | b: builtins.bool = ..., 88 | ne: Global___AnotherNested.NestedEnum.ValueType = ..., 89 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType = ..., 90 | ) -> None: ... 91 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["b", b"b", "ne", b"ne", "ne2", b"ne2", "s", b"s"] 92 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 93 | 94 | def __init__( 95 | self, 96 | ) -> None: ... 97 | 98 | Global___AnotherNested: typing_extensions.TypeAlias = AnotherNested 99 | -------------------------------------------------------------------------------- /test/generated_sync_only/testproto/nested/nested_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | """ 5 | 6 | import builtins 7 | import google.protobuf.descriptor 8 | import google.protobuf.internal.enum_type_wrapper 9 | import google.protobuf.message 10 | import sys 11 | import testproto.test3_pb2 12 | import typing 13 | 14 | if sys.version_info >= (3, 10): 15 | import typing as typing_extensions 16 | else: 17 | import typing_extensions 18 | 19 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 20 | 21 | @typing.final 22 | class Nested(google.protobuf.message.Message): 23 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 24 | 25 | A_FIELD_NUMBER: builtins.int 26 | a: testproto.test3_pb2.OuterEnum.ValueType 27 | def __init__( 28 | self, 29 | *, 30 | a: testproto.test3_pb2.OuterEnum.ValueType = ..., 31 | ) -> None: ... 32 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a", b"a"] 33 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 34 | 35 | Global___Nested: typing_extensions.TypeAlias = Nested 36 | 37 | @typing.final 38 | class AnotherNested(google.protobuf.message.Message): 39 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 40 | 41 | class _NestedEnum: 42 | ValueType = typing.NewType("ValueType", builtins.int) 43 | V: typing_extensions.TypeAlias = ValueType 44 | 45 | class _NestedEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested._NestedEnum.ValueType], builtins.type): 46 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 47 | INVALID: AnotherNested._NestedEnum.ValueType # 0 48 | ONE: AnotherNested._NestedEnum.ValueType # 1 49 | TWO: AnotherNested._NestedEnum.ValueType # 2 50 | 51 | class NestedEnum(_NestedEnum, metaclass=_NestedEnumEnumTypeWrapper): ... 52 | INVALID: AnotherNested.NestedEnum.ValueType # 0 53 | ONE: AnotherNested.NestedEnum.ValueType # 1 54 | TWO: AnotherNested.NestedEnum.ValueType # 2 55 | 56 | @typing.final 57 | class NestedMessage(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _NestedEnum2: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _NestedEnum2EnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[AnotherNested.NestedMessage._NestedEnum2.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | UNDEFINED: AnotherNested.NestedMessage._NestedEnum2.ValueType # 0 67 | NESTED_ENUM1: AnotherNested.NestedMessage._NestedEnum2.ValueType # 1 68 | NESTED_ENUM2: AnotherNested.NestedMessage._NestedEnum2.ValueType # 2 69 | 70 | class NestedEnum2(_NestedEnum2, metaclass=_NestedEnum2EnumTypeWrapper): ... 71 | UNDEFINED: AnotherNested.NestedMessage.NestedEnum2.ValueType # 0 72 | NESTED_ENUM1: AnotherNested.NestedMessage.NestedEnum2.ValueType # 1 73 | NESTED_ENUM2: AnotherNested.NestedMessage.NestedEnum2.ValueType # 2 74 | 75 | S_FIELD_NUMBER: builtins.int 76 | B_FIELD_NUMBER: builtins.int 77 | NE_FIELD_NUMBER: builtins.int 78 | NE2_FIELD_NUMBER: builtins.int 79 | s: builtins.str 80 | b: builtins.bool 81 | ne: Global___AnotherNested.NestedEnum.ValueType 82 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType 83 | def __init__( 84 | self, 85 | *, 86 | s: builtins.str = ..., 87 | b: builtins.bool = ..., 88 | ne: Global___AnotherNested.NestedEnum.ValueType = ..., 89 | ne2: Global___AnotherNested.NestedMessage.NestedEnum2.ValueType = ..., 90 | ) -> None: ... 91 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["b", b"b", "ne", b"ne", "ne2", b"ne2", "s", b"s"] 92 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 93 | 94 | def __init__( 95 | self, 96 | ) -> None: ... 97 | 98 | Global___AnotherNested: typing_extensions.TypeAlias = AnotherNested 99 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | # Run on git push, PR, or manually from the Actions tab 4 | on: 5 | push: 6 | branches: [main] 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | jobs: 11 | run_test: 12 | name: mypy-protobuf - ${{ matrix.py-ver-mypy-protobuf }} - unittest - ${{ matrix.py-ver-unit-tests }} - protobuf ${{ matrix.protobuf-version }} 13 | runs-on: ubuntu-24.04 14 | strategy: 15 | matrix: 16 | # Running mypy-protobuf itself 17 | py-ver-mypy-protobuf: 18 | - 3.9.17 19 | - 3.10.12 20 | - 3.11.4 21 | - 3.12.12 22 | - 3.13.9 23 | - 3.14.0 24 | # Running unit tests 25 | py-ver-unit-tests: 26 | - 3.9.17 27 | - 3.10.12 28 | - 3.11.4 29 | - 3.12.12 30 | - 3.13.9 31 | - 3.14.0 32 | protobuf-version: 33 | - 6.32.1 34 | - 6.33.1 35 | 36 | steps: 37 | - uses: actions/checkout@v6 38 | - name: Read version numbers 39 | run: | 40 | echo ::set-output name=PROTOBUF_VERSION::$(grep "^protobuf>=" test_requirements.txt | cut -f2 -d=) 41 | echo ::set-output name=PYRIGHT_VERSION::$(grep '"pyright"' .github/package.json | cut -d\" -f4) 42 | id: read_versions 43 | - name: Install uv 44 | uses: astral-sh/setup-uv@v7 45 | with: 46 | enable-cache: true # Optional: Enable caching for uv's package cache 47 | cache-dependency-glob: '**/*requirements.txt' # Optional: Specify a glob pattern to determine cache keys 48 | - name: Run Tests (./run_test.sh) 49 | env: 50 | PY_VER_MYPY_PROTOBUF: ${{matrix.py-ver-mypy-protobuf}} 51 | PY_VER_UNIT_TESTS: ${{matrix.py-ver-unit-tests}} 52 | PY_VER_MYPY: ${{matrix.py-ver-mypy-protobuf}} 53 | PYTHON_PROTOBUF_VERSION: ${{matrix.protobuf-version}} 54 | VALIDATE: 1 55 | run: | 56 | ./run_test.sh 57 | 58 | 59 | 60 | pyright: 61 | name: Pyright - ${{ matrix.python-version }} 62 | strategy: 63 | matrix: 64 | python-version: 65 | - 3.9.17 66 | - 3.10.12 67 | - 3.11.4 68 | - 3.12.12 69 | - 3.13.9 70 | - 3.14.0 71 | runs-on: ubuntu-24.04 72 | steps: 73 | - uses: actions/checkout@v6 74 | - name: Read version numbers 75 | run: | 76 | echo ::set-output name=PYRIGHT_VERSION::$(grep '"pyright"' .github/package.json | cut -d\" -f4) 77 | id: read_versions 78 | - name: Install uv 79 | uses: astral-sh/setup-uv@v7 80 | with: 81 | enable-cache: true # Optional: Enable caching for uv's package cache 82 | cache-dependency-glob: '**/*requirements.txt' # Optional: Specify a glob pattern to determine cache keys 83 | - run: | 84 | uv venv -p ${{ matrix.python-version }} 85 | uv pip install -r test_requirements.txt 86 | - name: Run Pyright 87 | uses: jakebailey/pyright-action@v2 88 | with: 89 | version: "${{ steps.read_versions.outputs.PYRIGHT_VERSION }}" 90 | python-path: .venv/bin/python3 91 | 92 | linting: 93 | name: Linting 94 | runs-on: ubuntu-latest 95 | steps: 96 | - uses: actions/checkout@v6 97 | - uses: actions/setup-python@v6 98 | with: 99 | python-version: "3.9" 100 | - name: Run formatters and linters 101 | run: | 102 | pip3 install black==24.3.0 isort flake8 flake8-pyi flake8-noqa flake8-bugbear 103 | black --check --extend-exclude '(_pb2_grpc|_pb2).pyi?$' . 104 | isort --check . --diff 105 | flake8 . 106 | - name: run shellcheck 107 | uses: reviewdog/action-shellcheck@v1 108 | with: 109 | # By default, shellcheck tries to make sure any external files referenced actually exist 110 | shellcheck_flags: -e SC1091 111 | 112 | sanity_check_windows: 113 | name: Sanity Check Windows Executable 114 | runs-on: windows-latest 115 | steps: 116 | - uses: actions/checkout@v6 117 | - uses: actions/setup-python@v6 118 | with: 119 | python-version: "3.9" 120 | - name: Read versions 121 | run: echo ::set-output name=PROTOBUF_VERSION::$(grep "^protobuf>=" test_requirements.txt | cut -f2 -d=) 122 | id: read_versions 123 | - name: Install Protoc 124 | uses: arduino/setup-protoc@v3 125 | with: 126 | version: "${{ steps.read_versions.outputs.PROTOBUF_VERSION }}" 127 | repo-token: ${{ secrets.GITHUB_TOKEN }} 128 | - name: Run Protoc 129 | run: | 130 | pip3 install -e . 131 | mkdir wintestout 132 | protoc --python_out=wintestout --mypy_out=wintestout proto\mypy_protobuf\extensions.proto 133 | -------------------------------------------------------------------------------- /proto/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option go_package = "github.com/golang/protobuf/ptypes/duration"; 38 | option java_package = "com.google.protobuf"; 39 | option java_outer_classname = "DurationProto"; 40 | option java_multiple_files = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Duration represents a signed, fixed-length span of time represented 44 | // as a count of seconds and fractions of seconds at nanosecond 45 | // resolution. It is independent of any calendar and concepts like "day" 46 | // or "month". It is related to Timestamp in that the difference between 47 | // two Timestamp values is a Duration and it can be added or subtracted 48 | // from a Timestamp. Range is approximately +-10,000 years. 49 | // 50 | // # Examples 51 | // 52 | // Example 1: Compute Duration from two Timestamps in pseudo code. 53 | // 54 | // Timestamp start = ...; 55 | // Timestamp end = ...; 56 | // Duration duration = ...; 57 | // 58 | // duration.seconds = end.seconds - start.seconds; 59 | // duration.nanos = end.nanos - start.nanos; 60 | // 61 | // if (duration.seconds < 0 && duration.nanos > 0) { 62 | // duration.seconds += 1; 63 | // duration.nanos -= 1000000000; 64 | // } else if (duration.seconds > 0 && duration.nanos < 0) { 65 | // duration.seconds -= 1; 66 | // duration.nanos += 1000000000; 67 | // } 68 | // 69 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 70 | // 71 | // Timestamp start = ...; 72 | // Duration duration = ...; 73 | // Timestamp end = ...; 74 | // 75 | // end.seconds = start.seconds + duration.seconds; 76 | // end.nanos = start.nanos + duration.nanos; 77 | // 78 | // if (end.nanos < 0) { 79 | // end.seconds -= 1; 80 | // end.nanos += 1000000000; 81 | // } else if (end.nanos >= 1000000000) { 82 | // end.seconds += 1; 83 | // end.nanos -= 1000000000; 84 | // } 85 | // 86 | // Example 3: Compute Duration from datetime.timedelta in Python. 87 | // 88 | // td = datetime.timedelta(days=3, minutes=10) 89 | // duration = Duration() 90 | // duration.FromTimedelta(td) 91 | // 92 | // # JSON Mapping 93 | // 94 | // In JSON format, the Duration type is encoded as a string rather than an 95 | // object, where the string ends in the suffix "s" (indicating seconds) and 96 | // is preceded by the number of seconds, with nanoseconds expressed as 97 | // fractional seconds. For example, 3 seconds with 0 nanoseconds should be 98 | // encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 99 | // be expressed in JSON format as "3.000000001s", and 3 seconds and 1 100 | // microsecond should be expressed in JSON format as "3.000001s". 101 | // 102 | // 103 | message Duration { 104 | // Signed seconds of the span of time. Must be from -315,576,000,000 105 | // to +315,576,000,000 inclusive. Note: these bounds are computed from: 106 | // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 107 | int64 seconds = 1; 108 | 109 | // Signed fractions of a second at nanosecond resolution of the span 110 | // of time. Durations less than one second are represented with a 0 111 | // `seconds` field and a positive or negative `nanos` field. For durations 112 | // of one second or more, a non-zero value for the `nanos` field must be 113 | // of the same sign as the `seconds` field. Must be from -999,999,999 114 | // to +999,999,999 inclusive. 115 | int32 nanos = 2; 116 | } 117 | -------------------------------------------------------------------------------- /proto/testproto/test.proto: -------------------------------------------------------------------------------- 1 | // Proto 2 test file. 2 | syntax = "proto2"; 3 | 4 | package test; 5 | 6 | import "mypy_protobuf/extensions.proto"; 7 | import "testproto/inner/inner.proto"; 8 | import "testproto/nested/nested.proto"; 9 | import "testproto/nopackage.proto"; 10 | import "testproto/test3.proto"; 11 | 12 | // Outer Enum 13 | enum OuterEnum { 14 | // FOO 15 | FOO = 1; 16 | // BAR 17 | BAR = 2; 18 | } 19 | 20 | // Naming conflicts! 21 | enum NamingConflicts { 22 | Name = 1; 23 | Value = 2; 24 | keys = 3; 25 | values = 4; 26 | items = 5; 27 | // See https://github.com/protocolbuffers/protobuf/issues/8803 28 | // proto itself generates broken code when DESCRIPTOR is there 29 | // DESCRIPTOR = 8; 30 | } 31 | 32 | // Message with one of everything 33 | message Simple1 { 34 | // Inner Enum 35 | enum InnerEnum { 36 | // INNER1 37 | INNER1 = 1; 38 | // INNER2 39 | INNER2 = 2; 40 | } 41 | message InnerMessage {} 42 | 43 | optional string a_string = 1; 44 | repeated string a_repeated_string = 2; 45 | optional bool a_boolean = 3; 46 | optional uint32 a_uint32 = 4; 47 | optional OuterEnum a_enum = 5; 48 | optional test3.OuterEnum a_external_enum = 6; 49 | 50 | optional inner.Inner a_inner = 7; 51 | optional test.nested_package.Nested a_nested = 12; 52 | 53 | optional InnerEnum inner_enum = 8; 54 | repeated InnerEnum rep_inner_enum = 9; 55 | optional InnerMessage inner_message = 10; 56 | repeated InnerMessage rep_inner_message = 11; 57 | 58 | optional NoPackage no_package = 13; 59 | optional test.nested_package.AnotherNested.NestedEnum nested_enum = 14; 60 | optional test.nested_package.AnotherNested.NestedMessage nested_message = 15; 61 | 62 | oneof a_oneof { 63 | string a_oneof_1 = 16; 64 | string a_oneof_2 = 17; 65 | Simple2 outer_message_in_oneof = 18; 66 | OuterEnum outer_enum_in_oneof = 19; 67 | InnerEnum inner_enum_in_oneof = 20; 68 | } 69 | 70 | optional uint32 user_id = 21 [(mypy_protobuf.casttype)="test/test_generated_mypy.UserId"]; 71 | optional string email = 22 [(mypy_protobuf.casttype)="test/test_generated_mypy.Email"]; 72 | map email_by_uid = 23 [ 73 | (mypy_protobuf.keytype)="test/test_generated_mypy.UserId", 74 | (mypy_protobuf.valuetype)="test/test_generated_mypy.Email" 75 | ]; 76 | 77 | extensions 1000 to max; 78 | } 79 | 80 | message Simple2 { 81 | required string a_string = 1; 82 | 83 | extensions 1000 to max; 84 | } 85 | 86 | message Extensions1 { 87 | extend Simple1 { 88 | // ext 89 | optional Extensions1 ext = 1000; 90 | } 91 | 92 | optional string ext1_string = 1; 93 | } 94 | 95 | message Extensions2 { 96 | extend Simple1 { 97 | // foo 98 | optional Extensions2 foo = 2020; 99 | } 100 | 101 | optional bool flag = 1; 102 | } 103 | 104 | message None { 105 | optional int64 valid = 1; 106 | } 107 | 108 | message PythonReservedKeywords { 109 | enum finally { 110 | continue = 1; 111 | valid_in_finally = 2; 112 | } 113 | 114 | message lambda { 115 | optional int64 continue = 1; 116 | optional int64 valid = 2; 117 | } 118 | 119 | required int64 from = 1; 120 | optional Simple2 in = 2; 121 | optional finally is = 3; 122 | optional int64 for = 5; 123 | optional int64 try = 6; 124 | optional int64 def = 7; 125 | optional int64 nonlocal = 8; 126 | optional int64 while = 9; 127 | optional int64 and = 10; 128 | optional int64 del = 11; 129 | optional int64 global = 12; 130 | optional int64 not = 13; 131 | optional int64 with = 14; 132 | optional int64 as = 15; 133 | optional int64 elif = 16; 134 | optional int64 if = 17; 135 | optional int64 or = 18; 136 | optional int64 yield = 19; 137 | optional int64 assert = 20; 138 | optional int64 else = 21; 139 | optional int64 import = 22; 140 | optional int64 pass = 23; 141 | optional int64 break = 24; 142 | optional int64 except = 25; 143 | optional int64 raise = 26; 144 | optional int64 False = 27; 145 | optional int64 True = 29; 146 | optional int64 class = 30; 147 | 148 | // Test unreserved identifiers w/ reserved message names 149 | optional None none = 28; 150 | optional finally valid = 31; 151 | } 152 | 153 | // Do one with just one arg - to make sure it's syntactically correct 154 | message PythonReservedKeywordsSmall { 155 | required int64 from = 1; 156 | } 157 | 158 | // Method name is reserved 159 | service PythonReservedKeywordsService { 160 | // lambda 161 | rpc lambda(Simple1) returns (PythonReservedKeywords.lambda) {} 162 | // valid_method_name1 163 | rpc valid_method_name1(Simple1) returns (None) {} 164 | // valid_method_name2 165 | rpc valid_method_name2(Simple1) returns (PythonReservedKeywords.lambda) {} 166 | } 167 | 168 | message SelfField { 169 | // Field self -> must generate an __init__ method w/ different name 170 | optional int64 self = 1; 171 | } 172 | 173 | message DeprecatedMessage { 174 | // This message is deprecated 175 | option deprecated = true; 176 | 177 | optional string a_string = 1; 178 | } 179 | 180 | message DeprecatedMessageBadComment { 181 | // This message is deprecated 182 | // """ triple quotes in comment 183 | option deprecated = true; 184 | 185 | optional string a_string = 1; 186 | } 187 | 188 | enum DeprecatedEnum { 189 | // This enum is deprecated 190 | // 2 lines of comments 191 | // "Quotes in comments" 192 | // and 'single quotes' 193 | option deprecated = true; 194 | // Trailing comment 195 | 196 | DEPRECATED_ONE = 1; 197 | DEPRECATED_TWO = 2; 198 | } 199 | -------------------------------------------------------------------------------- /test/generated/google/protobuf/duration_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Protocol Buffers - Google's data interchange format 5 | Copyright 2008 Google Inc. All rights reserved. 6 | https://developers.google.com/protocol-buffers/ 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are 10 | met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other materials provided with the 17 | distribution. 18 | * Neither the name of Google Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | """ 34 | 35 | import builtins 36 | import google.protobuf.descriptor 37 | import google.protobuf.internal.well_known_types 38 | import google.protobuf.message 39 | import sys 40 | import typing 41 | 42 | if sys.version_info >= (3, 10): 43 | import typing as typing_extensions 44 | else: 45 | import typing_extensions 46 | 47 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 48 | 49 | @typing.final 50 | class Duration(google.protobuf.message.Message, google.protobuf.internal.well_known_types.Duration): 51 | """A Duration represents a signed, fixed-length span of time represented 52 | as a count of seconds and fractions of seconds at nanosecond 53 | resolution. It is independent of any calendar and concepts like "day" 54 | or "month". It is related to Timestamp in that the difference between 55 | two Timestamp values is a Duration and it can be added or subtracted 56 | from a Timestamp. Range is approximately +-10,000 years. 57 | 58 | # Examples 59 | 60 | Example 1: Compute Duration from two Timestamps in pseudo code. 61 | 62 | Timestamp start = ...; 63 | Timestamp end = ...; 64 | Duration duration = ...; 65 | 66 | duration.seconds = end.seconds - start.seconds; 67 | duration.nanos = end.nanos - start.nanos; 68 | 69 | if (duration.seconds < 0 && duration.nanos > 0) { 70 | duration.seconds += 1; 71 | duration.nanos -= 1000000000; 72 | } else if (duration.seconds > 0 && duration.nanos < 0) { 73 | duration.seconds -= 1; 74 | duration.nanos += 1000000000; 75 | } 76 | 77 | Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 78 | 79 | Timestamp start = ...; 80 | Duration duration = ...; 81 | Timestamp end = ...; 82 | 83 | end.seconds = start.seconds + duration.seconds; 84 | end.nanos = start.nanos + duration.nanos; 85 | 86 | if (end.nanos < 0) { 87 | end.seconds -= 1; 88 | end.nanos += 1000000000; 89 | } else if (end.nanos >= 1000000000) { 90 | end.seconds += 1; 91 | end.nanos -= 1000000000; 92 | } 93 | 94 | Example 3: Compute Duration from datetime.timedelta in Python. 95 | 96 | td = datetime.timedelta(days=3, minutes=10) 97 | duration = Duration() 98 | duration.FromTimedelta(td) 99 | 100 | # JSON Mapping 101 | 102 | In JSON format, the Duration type is encoded as a string rather than an 103 | object, where the string ends in the suffix "s" (indicating seconds) and 104 | is preceded by the number of seconds, with nanoseconds expressed as 105 | fractional seconds. For example, 3 seconds with 0 nanoseconds should be 106 | encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 107 | be expressed in JSON format as "3.000000001s", and 3 seconds and 1 108 | microsecond should be expressed in JSON format as "3.000001s". 109 | """ 110 | 111 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 112 | 113 | SECONDS_FIELD_NUMBER: builtins.int 114 | NANOS_FIELD_NUMBER: builtins.int 115 | seconds: builtins.int 116 | """Signed seconds of the span of time. Must be from -315,576,000,000 117 | to +315,576,000,000 inclusive. Note: these bounds are computed from: 118 | 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 119 | """ 120 | nanos: builtins.int 121 | """Signed fractions of a second at nanosecond resolution of the span 122 | of time. Durations less than one second are represented with a 0 123 | `seconds` field and a positive or negative `nanos` field. For durations 124 | of one second or more, a non-zero value for the `nanos` field must be 125 | of the same sign as the `seconds` field. Must be from -999,999,999 126 | to +999,999,999 inclusive. 127 | """ 128 | def __init__( 129 | self, 130 | *, 131 | seconds: builtins.int = ..., 132 | nanos: builtins.int = ..., 133 | ) -> None: ... 134 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["nanos", b"nanos", "seconds", b"seconds"] 135 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 136 | 137 | Global___Duration: typing_extensions.TypeAlias = Duration 138 | -------------------------------------------------------------------------------- /test/generated_concrete/google/protobuf/duration_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | Protocol Buffers - Google's data interchange format 5 | Copyright 2008 Google Inc. All rights reserved. 6 | https://developers.google.com/protocol-buffers/ 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are 10 | met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other materials provided with the 17 | distribution. 18 | * Neither the name of Google Inc. nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | """ 34 | 35 | import builtins 36 | import google.protobuf.descriptor 37 | import google.protobuf.internal.well_known_types 38 | import google.protobuf.message 39 | import sys 40 | import typing 41 | 42 | if sys.version_info >= (3, 10): 43 | import typing as typing_extensions 44 | else: 45 | import typing_extensions 46 | 47 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 48 | 49 | @typing.final 50 | class Duration(google.protobuf.message.Message, google.protobuf.internal.well_known_types.Duration): 51 | """A Duration represents a signed, fixed-length span of time represented 52 | as a count of seconds and fractions of seconds at nanosecond 53 | resolution. It is independent of any calendar and concepts like "day" 54 | or "month". It is related to Timestamp in that the difference between 55 | two Timestamp values is a Duration and it can be added or subtracted 56 | from a Timestamp. Range is approximately +-10,000 years. 57 | 58 | # Examples 59 | 60 | Example 1: Compute Duration from two Timestamps in pseudo code. 61 | 62 | Timestamp start = ...; 63 | Timestamp end = ...; 64 | Duration duration = ...; 65 | 66 | duration.seconds = end.seconds - start.seconds; 67 | duration.nanos = end.nanos - start.nanos; 68 | 69 | if (duration.seconds < 0 && duration.nanos > 0) { 70 | duration.seconds += 1; 71 | duration.nanos -= 1000000000; 72 | } else if (duration.seconds > 0 && duration.nanos < 0) { 73 | duration.seconds -= 1; 74 | duration.nanos += 1000000000; 75 | } 76 | 77 | Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 78 | 79 | Timestamp start = ...; 80 | Duration duration = ...; 81 | Timestamp end = ...; 82 | 83 | end.seconds = start.seconds + duration.seconds; 84 | end.nanos = start.nanos + duration.nanos; 85 | 86 | if (end.nanos < 0) { 87 | end.seconds -= 1; 88 | end.nanos += 1000000000; 89 | } else if (end.nanos >= 1000000000) { 90 | end.seconds += 1; 91 | end.nanos -= 1000000000; 92 | } 93 | 94 | Example 3: Compute Duration from datetime.timedelta in Python. 95 | 96 | td = datetime.timedelta(days=3, minutes=10) 97 | duration = Duration() 98 | duration.FromTimedelta(td) 99 | 100 | # JSON Mapping 101 | 102 | In JSON format, the Duration type is encoded as a string rather than an 103 | object, where the string ends in the suffix "s" (indicating seconds) and 104 | is preceded by the number of seconds, with nanoseconds expressed as 105 | fractional seconds. For example, 3 seconds with 0 nanoseconds should be 106 | encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 107 | be expressed in JSON format as "3.000000001s", and 3 seconds and 1 108 | microsecond should be expressed in JSON format as "3.000001s". 109 | """ 110 | 111 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 112 | 113 | SECONDS_FIELD_NUMBER: builtins.int 114 | NANOS_FIELD_NUMBER: builtins.int 115 | seconds: builtins.int 116 | """Signed seconds of the span of time. Must be from -315,576,000,000 117 | to +315,576,000,000 inclusive. Note: these bounds are computed from: 118 | 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 119 | """ 120 | nanos: builtins.int 121 | """Signed fractions of a second at nanosecond resolution of the span 122 | of time. Durations less than one second are represented with a 0 123 | `seconds` field and a positive or negative `nanos` field. For durations 124 | of one second or more, a non-zero value for the `nanos` field must be 125 | of the same sign as the `seconds` field. Must be from -999,999,999 126 | to +999,999,999 inclusive. 127 | """ 128 | def __init__( 129 | self, 130 | *, 131 | seconds: builtins.int = ..., 132 | nanos: builtins.int = ..., 133 | ) -> None: ... 134 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["nanos", b"nanos", "seconds", b"seconds"] 135 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 136 | 137 | Global___Duration: typing_extensions.TypeAlias = Duration 138 | -------------------------------------------------------------------------------- /test/generated/testproto/test3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | package test3""" 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.enum_type_wrapper 11 | import google.protobuf.message 12 | import sys 13 | import test.test_generated_mypy 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | class _OuterEnum: 24 | ValueType = typing.NewType("ValueType", builtins.int) 25 | V: typing_extensions.TypeAlias = ValueType 26 | 27 | class _OuterEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_OuterEnum.ValueType], builtins.type): 28 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 29 | UNKNOWN: _OuterEnum.ValueType # 0 30 | FOO3: _OuterEnum.ValueType # 1 31 | BAR3: _OuterEnum.ValueType # 2 32 | 33 | class OuterEnum(_OuterEnum, metaclass=_OuterEnumEnumTypeWrapper): ... 34 | 35 | UNKNOWN: OuterEnum.ValueType # 0 36 | FOO3: OuterEnum.ValueType # 1 37 | BAR3: OuterEnum.ValueType # 2 38 | Global___OuterEnum: typing_extensions.TypeAlias = OuterEnum 39 | 40 | @typing.final 41 | class OuterMessage3(google.protobuf.message.Message): 42 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 43 | 44 | A_STRING_FIELD_NUMBER: builtins.int 45 | a_string: builtins.str 46 | def __init__( 47 | self, 48 | *, 49 | a_string: builtins.str = ..., 50 | ) -> None: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___OuterMessage3: typing_extensions.TypeAlias = OuterMessage3 55 | 56 | @typing.final 57 | class SimpleProto3(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _InnerEnum: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _InnerEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[SimpleProto3._InnerEnum.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | INNER1: SimpleProto3._InnerEnum.ValueType # 0 67 | INNER2: SimpleProto3._InnerEnum.ValueType # 1 68 | 69 | class InnerEnum(_InnerEnum, metaclass=_InnerEnumEnumTypeWrapper): ... 70 | INNER1: SimpleProto3.InnerEnum.ValueType # 0 71 | INNER2: SimpleProto3.InnerEnum.ValueType # 1 72 | 73 | @typing.final 74 | class MapScalarEntry(google.protobuf.message.Message): 75 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 76 | 77 | KEY_FIELD_NUMBER: builtins.int 78 | VALUE_FIELD_NUMBER: builtins.int 79 | key: builtins.int 80 | value: builtins.str 81 | def __init__( 82 | self, 83 | *, 84 | key: builtins.int = ..., 85 | value: builtins.str = ..., 86 | ) -> None: ... 87 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 88 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 89 | 90 | @typing.final 91 | class MapMessageEntry(google.protobuf.message.Message): 92 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 93 | 94 | KEY_FIELD_NUMBER: builtins.int 95 | VALUE_FIELD_NUMBER: builtins.int 96 | key: builtins.int 97 | @property 98 | def value(self) -> Global___OuterMessage3: ... 99 | def __init__( 100 | self, 101 | *, 102 | key: builtins.int = ..., 103 | value: Global___OuterMessage3 | None = ..., 104 | ) -> None: ... 105 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["value", b"value"] 106 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 107 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 108 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 109 | 110 | @typing.final 111 | class EmailByUidEntry(google.protobuf.message.Message): 112 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 113 | 114 | KEY_FIELD_NUMBER: builtins.int 115 | VALUE_FIELD_NUMBER: builtins.int 116 | key: builtins.int 117 | value: builtins.str 118 | def __init__( 119 | self, 120 | *, 121 | key: builtins.int = ..., 122 | value: builtins.str = ..., 123 | ) -> None: ... 124 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 125 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 126 | 127 | A_STRING_FIELD_NUMBER: builtins.int 128 | A_REPEATED_STRING_FIELD_NUMBER: builtins.int 129 | A_OUTER_ENUM_FIELD_NUMBER: builtins.int 130 | OUTER_MESSAGE_FIELD_NUMBER: builtins.int 131 | INNER_ENUM_FIELD_NUMBER: builtins.int 132 | A_ONEOF_1_FIELD_NUMBER: builtins.int 133 | A_ONEOF_2_FIELD_NUMBER: builtins.int 134 | OUTER_MESSAGE_IN_ONEOF_FIELD_NUMBER: builtins.int 135 | OUTER_ENUM_IN_ONEOF_FIELD_NUMBER: builtins.int 136 | INNER_ENUM_IN_ONEOF_FIELD_NUMBER: builtins.int 137 | B_ONEOF_1_FIELD_NUMBER: builtins.int 138 | B_ONEOF_2_FIELD_NUMBER: builtins.int 139 | BOOL_FIELD_NUMBER: builtins.int 140 | OUTERENUM_FIELD_NUMBER: builtins.int 141 | OUTERMESSAGE3_FIELD_NUMBER: builtins.int 142 | MAP_SCALAR_FIELD_NUMBER: builtins.int 143 | MAP_MESSAGE_FIELD_NUMBER: builtins.int 144 | AN_OPTIONAL_STRING_FIELD_NUMBER: builtins.int 145 | USER_ID_FIELD_NUMBER: builtins.int 146 | EMAIL_FIELD_NUMBER: builtins.int 147 | EMAIL_BY_UID_FIELD_NUMBER: builtins.int 148 | a_string: builtins.str 149 | a_outer_enum: Global___OuterEnum.ValueType 150 | inner_enum: Global___SimpleProto3.InnerEnum.ValueType 151 | a_oneof_1: builtins.str 152 | a_oneof_2: builtins.str 153 | outer_enum_in_oneof: Global___OuterEnum.ValueType 154 | inner_enum_in_oneof: Global___SimpleProto3.InnerEnum.ValueType 155 | b_oneof_1: builtins.str 156 | b_oneof_2: builtins.str 157 | OuterEnum: Global___OuterEnum.ValueType 158 | """Test having fieldname match messagename""" 159 | an_optional_string: builtins.str 160 | user_id: test.test_generated_mypy.UserId 161 | email: test.test_generated_mypy.Email 162 | @property 163 | def a_repeated_string(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... 164 | @property 165 | def outer_message(self) -> Global___OuterMessage3: ... 166 | @property 167 | def outer_message_in_oneof(self) -> Global___OuterMessage3: ... 168 | @property 169 | def bool(self) -> Global___OuterMessage3: ... 170 | @property 171 | def OuterMessage3(self) -> Global___OuterMessage3: ... 172 | @property 173 | def map_scalar(self) -> google.protobuf.internal.containers.ScalarMap[builtins.int, builtins.str]: 174 | """Test generation of map""" 175 | 176 | @property 177 | def map_message(self) -> google.protobuf.internal.containers.MessageMap[builtins.int, Global___OuterMessage3]: ... 178 | @property 179 | def email_by_uid(self) -> google.protobuf.internal.containers.ScalarMap[test.test_generated_mypy.UserId, test.test_generated_mypy.Email]: ... 180 | def __init__( 181 | self, 182 | *, 183 | a_string: builtins.str = ..., 184 | a_repeated_string: collections.abc.Iterable[builtins.str] | None = ..., 185 | a_outer_enum: Global___OuterEnum.ValueType = ..., 186 | outer_message: Global___OuterMessage3 | None = ..., 187 | inner_enum: Global___SimpleProto3.InnerEnum.ValueType = ..., 188 | a_oneof_1: builtins.str = ..., 189 | a_oneof_2: builtins.str = ..., 190 | outer_message_in_oneof: Global___OuterMessage3 | None = ..., 191 | outer_enum_in_oneof: Global___OuterEnum.ValueType = ..., 192 | inner_enum_in_oneof: Global___SimpleProto3.InnerEnum.ValueType = ..., 193 | b_oneof_1: builtins.str = ..., 194 | b_oneof_2: builtins.str = ..., 195 | bool: Global___OuterMessage3 | None = ..., 196 | OuterEnum: Global___OuterEnum.ValueType = ..., 197 | OuterMessage3: Global___OuterMessage3 | None = ..., 198 | map_scalar: collections.abc.Mapping[builtins.int, builtins.str] | None = ..., 199 | map_message: collections.abc.Mapping[builtins.int, Global___OuterMessage3] | None = ..., 200 | an_optional_string: builtins.str | None = ..., 201 | user_id: test.test_generated_mypy.UserId = ..., 202 | email: test.test_generated_mypy.Email = ..., 203 | email_by_uid: collections.abc.Mapping[test.test_generated_mypy.UserId, test.test_generated_mypy.Email] | None = ..., 204 | ) -> None: ... 205 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["OuterMessage3", b"OuterMessage3", "_an_optional_string", b"_an_optional_string", "a_oneof", b"a_oneof", "a_oneof_1", b"a_oneof_1", "a_oneof_2", b"a_oneof_2", "an_optional_string", b"an_optional_string", "b_oneof", b"b_oneof", "b_oneof_1", b"b_oneof_1", "b_oneof_2", b"b_oneof_2", "bool", b"bool", "inner_enum_in_oneof", b"inner_enum_in_oneof", "outer_enum_in_oneof", b"outer_enum_in_oneof", "outer_message", b"outer_message", "outer_message_in_oneof", b"outer_message_in_oneof"] 206 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 207 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["OuterEnum", b"OuterEnum", "OuterMessage3", b"OuterMessage3", "_an_optional_string", b"_an_optional_string", "a_oneof", b"a_oneof", "a_oneof_1", b"a_oneof_1", "a_oneof_2", b"a_oneof_2", "a_outer_enum", b"a_outer_enum", "a_repeated_string", b"a_repeated_string", "a_string", b"a_string", "an_optional_string", b"an_optional_string", "b_oneof", b"b_oneof", "b_oneof_1", b"b_oneof_1", "b_oneof_2", b"b_oneof_2", "bool", b"bool", "email", b"email", "email_by_uid", b"email_by_uid", "inner_enum", b"inner_enum", "inner_enum_in_oneof", b"inner_enum_in_oneof", "map_message", b"map_message", "map_scalar", b"map_scalar", "outer_enum_in_oneof", b"outer_enum_in_oneof", "outer_message", b"outer_message", "outer_message_in_oneof", b"outer_message_in_oneof", "user_id", b"user_id"] 208 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 209 | _WhichOneofReturnType__an_optional_string: typing_extensions.TypeAlias = typing.Literal["an_optional_string"] 210 | _WhichOneofArgType__an_optional_string: typing_extensions.TypeAlias = typing.Literal["_an_optional_string", b"_an_optional_string"] 211 | _WhichOneofReturnType_a_oneof: typing_extensions.TypeAlias = typing.Literal["a_oneof_1", "a_oneof_2", "outer_message_in_oneof", "outer_enum_in_oneof", "inner_enum_in_oneof"] 212 | _WhichOneofArgType_a_oneof: typing_extensions.TypeAlias = typing.Literal["a_oneof", b"a_oneof"] 213 | _WhichOneofReturnType_b_oneof: typing_extensions.TypeAlias = typing.Literal["b_oneof_1", "b_oneof_2"] 214 | _WhichOneofArgType_b_oneof: typing_extensions.TypeAlias = typing.Literal["b_oneof", b"b_oneof"] 215 | @typing.overload 216 | def WhichOneof(self, oneof_group: _WhichOneofArgType__an_optional_string) -> _WhichOneofReturnType__an_optional_string | None: ... 217 | @typing.overload 218 | def WhichOneof(self, oneof_group: _WhichOneofArgType_a_oneof) -> _WhichOneofReturnType_a_oneof | None: ... 219 | @typing.overload 220 | def WhichOneof(self, oneof_group: _WhichOneofArgType_b_oneof) -> _WhichOneofReturnType_b_oneof | None: ... 221 | 222 | Global___SimpleProto3: typing_extensions.TypeAlias = SimpleProto3 223 | -------------------------------------------------------------------------------- /test/generated_async_only/testproto/test3_pb2.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | @generated by mypy-protobuf. Do not edit manually! 3 | isort:skip_file 4 | package test3""" 5 | 6 | import builtins 7 | import collections.abc 8 | import google.protobuf.descriptor 9 | import google.protobuf.internal.containers 10 | import google.protobuf.internal.enum_type_wrapper 11 | import google.protobuf.message 12 | import sys 13 | import test.test_generated_mypy 14 | import typing 15 | 16 | if sys.version_info >= (3, 10): 17 | import typing as typing_extensions 18 | else: 19 | import typing_extensions 20 | 21 | DESCRIPTOR: google.protobuf.descriptor.FileDescriptor 22 | 23 | class _OuterEnum: 24 | ValueType = typing.NewType("ValueType", builtins.int) 25 | V: typing_extensions.TypeAlias = ValueType 26 | 27 | class _OuterEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_OuterEnum.ValueType], builtins.type): 28 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 29 | UNKNOWN: _OuterEnum.ValueType # 0 30 | FOO3: _OuterEnum.ValueType # 1 31 | BAR3: _OuterEnum.ValueType # 2 32 | 33 | class OuterEnum(_OuterEnum, metaclass=_OuterEnumEnumTypeWrapper): ... 34 | 35 | UNKNOWN: OuterEnum.ValueType # 0 36 | FOO3: OuterEnum.ValueType # 1 37 | BAR3: OuterEnum.ValueType # 2 38 | Global___OuterEnum: typing_extensions.TypeAlias = OuterEnum 39 | 40 | @typing.final 41 | class OuterMessage3(google.protobuf.message.Message): 42 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 43 | 44 | A_STRING_FIELD_NUMBER: builtins.int 45 | a_string: builtins.str 46 | def __init__( 47 | self, 48 | *, 49 | a_string: builtins.str = ..., 50 | ) -> None: ... 51 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["a_string", b"a_string"] 52 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 53 | 54 | Global___OuterMessage3: typing_extensions.TypeAlias = OuterMessage3 55 | 56 | @typing.final 57 | class SimpleProto3(google.protobuf.message.Message): 58 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 59 | 60 | class _InnerEnum: 61 | ValueType = typing.NewType("ValueType", builtins.int) 62 | V: typing_extensions.TypeAlias = ValueType 63 | 64 | class _InnerEnumEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[SimpleProto3._InnerEnum.ValueType], builtins.type): 65 | DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor 66 | INNER1: SimpleProto3._InnerEnum.ValueType # 0 67 | INNER2: SimpleProto3._InnerEnum.ValueType # 1 68 | 69 | class InnerEnum(_InnerEnum, metaclass=_InnerEnumEnumTypeWrapper): ... 70 | INNER1: SimpleProto3.InnerEnum.ValueType # 0 71 | INNER2: SimpleProto3.InnerEnum.ValueType # 1 72 | 73 | @typing.final 74 | class MapScalarEntry(google.protobuf.message.Message): 75 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 76 | 77 | KEY_FIELD_NUMBER: builtins.int 78 | VALUE_FIELD_NUMBER: builtins.int 79 | key: builtins.int 80 | value: builtins.str 81 | def __init__( 82 | self, 83 | *, 84 | key: builtins.int = ..., 85 | value: builtins.str = ..., 86 | ) -> None: ... 87 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 88 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 89 | 90 | @typing.final 91 | class MapMessageEntry(google.protobuf.message.Message): 92 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 93 | 94 | KEY_FIELD_NUMBER: builtins.int 95 | VALUE_FIELD_NUMBER: builtins.int 96 | key: builtins.int 97 | @property 98 | def value(self) -> Global___OuterMessage3: ... 99 | def __init__( 100 | self, 101 | *, 102 | key: builtins.int = ..., 103 | value: Global___OuterMessage3 | None = ..., 104 | ) -> None: ... 105 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["value", b"value"] 106 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 107 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 108 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 109 | 110 | @typing.final 111 | class EmailByUidEntry(google.protobuf.message.Message): 112 | DESCRIPTOR: google.protobuf.descriptor.Descriptor 113 | 114 | KEY_FIELD_NUMBER: builtins.int 115 | VALUE_FIELD_NUMBER: builtins.int 116 | key: builtins.int 117 | value: builtins.str 118 | def __init__( 119 | self, 120 | *, 121 | key: builtins.int = ..., 122 | value: builtins.str = ..., 123 | ) -> None: ... 124 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["key", b"key", "value", b"value"] 125 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 126 | 127 | A_STRING_FIELD_NUMBER: builtins.int 128 | A_REPEATED_STRING_FIELD_NUMBER: builtins.int 129 | A_OUTER_ENUM_FIELD_NUMBER: builtins.int 130 | OUTER_MESSAGE_FIELD_NUMBER: builtins.int 131 | INNER_ENUM_FIELD_NUMBER: builtins.int 132 | A_ONEOF_1_FIELD_NUMBER: builtins.int 133 | A_ONEOF_2_FIELD_NUMBER: builtins.int 134 | OUTER_MESSAGE_IN_ONEOF_FIELD_NUMBER: builtins.int 135 | OUTER_ENUM_IN_ONEOF_FIELD_NUMBER: builtins.int 136 | INNER_ENUM_IN_ONEOF_FIELD_NUMBER: builtins.int 137 | B_ONEOF_1_FIELD_NUMBER: builtins.int 138 | B_ONEOF_2_FIELD_NUMBER: builtins.int 139 | BOOL_FIELD_NUMBER: builtins.int 140 | OUTERENUM_FIELD_NUMBER: builtins.int 141 | OUTERMESSAGE3_FIELD_NUMBER: builtins.int 142 | MAP_SCALAR_FIELD_NUMBER: builtins.int 143 | MAP_MESSAGE_FIELD_NUMBER: builtins.int 144 | AN_OPTIONAL_STRING_FIELD_NUMBER: builtins.int 145 | USER_ID_FIELD_NUMBER: builtins.int 146 | EMAIL_FIELD_NUMBER: builtins.int 147 | EMAIL_BY_UID_FIELD_NUMBER: builtins.int 148 | a_string: builtins.str 149 | a_outer_enum: Global___OuterEnum.ValueType 150 | inner_enum: Global___SimpleProto3.InnerEnum.ValueType 151 | a_oneof_1: builtins.str 152 | a_oneof_2: builtins.str 153 | outer_enum_in_oneof: Global___OuterEnum.ValueType 154 | inner_enum_in_oneof: Global___SimpleProto3.InnerEnum.ValueType 155 | b_oneof_1: builtins.str 156 | b_oneof_2: builtins.str 157 | OuterEnum: Global___OuterEnum.ValueType 158 | """Test having fieldname match messagename""" 159 | an_optional_string: builtins.str 160 | user_id: test.test_generated_mypy.UserId 161 | email: test.test_generated_mypy.Email 162 | @property 163 | def a_repeated_string(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... 164 | @property 165 | def outer_message(self) -> Global___OuterMessage3: ... 166 | @property 167 | def outer_message_in_oneof(self) -> Global___OuterMessage3: ... 168 | @property 169 | def bool(self) -> Global___OuterMessage3: ... 170 | @property 171 | def OuterMessage3(self) -> Global___OuterMessage3: ... 172 | @property 173 | def map_scalar(self) -> google.protobuf.internal.containers.ScalarMap[builtins.int, builtins.str]: 174 | """Test generation of map""" 175 | 176 | @property 177 | def map_message(self) -> google.protobuf.internal.containers.MessageMap[builtins.int, Global___OuterMessage3]: ... 178 | @property 179 | def email_by_uid(self) -> google.protobuf.internal.containers.ScalarMap[test.test_generated_mypy.UserId, test.test_generated_mypy.Email]: ... 180 | def __init__( 181 | self, 182 | *, 183 | a_string: builtins.str = ..., 184 | a_repeated_string: collections.abc.Iterable[builtins.str] | None = ..., 185 | a_outer_enum: Global___OuterEnum.ValueType = ..., 186 | outer_message: Global___OuterMessage3 | None = ..., 187 | inner_enum: Global___SimpleProto3.InnerEnum.ValueType = ..., 188 | a_oneof_1: builtins.str = ..., 189 | a_oneof_2: builtins.str = ..., 190 | outer_message_in_oneof: Global___OuterMessage3 | None = ..., 191 | outer_enum_in_oneof: Global___OuterEnum.ValueType = ..., 192 | inner_enum_in_oneof: Global___SimpleProto3.InnerEnum.ValueType = ..., 193 | b_oneof_1: builtins.str = ..., 194 | b_oneof_2: builtins.str = ..., 195 | bool: Global___OuterMessage3 | None = ..., 196 | OuterEnum: Global___OuterEnum.ValueType = ..., 197 | OuterMessage3: Global___OuterMessage3 | None = ..., 198 | map_scalar: collections.abc.Mapping[builtins.int, builtins.str] | None = ..., 199 | map_message: collections.abc.Mapping[builtins.int, Global___OuterMessage3] | None = ..., 200 | an_optional_string: builtins.str | None = ..., 201 | user_id: test.test_generated_mypy.UserId = ..., 202 | email: test.test_generated_mypy.Email = ..., 203 | email_by_uid: collections.abc.Mapping[test.test_generated_mypy.UserId, test.test_generated_mypy.Email] | None = ..., 204 | ) -> None: ... 205 | _HasFieldArgType: typing_extensions.TypeAlias = typing.Literal["OuterMessage3", b"OuterMessage3", "_an_optional_string", b"_an_optional_string", "a_oneof", b"a_oneof", "a_oneof_1", b"a_oneof_1", "a_oneof_2", b"a_oneof_2", "an_optional_string", b"an_optional_string", "b_oneof", b"b_oneof", "b_oneof_1", b"b_oneof_1", "b_oneof_2", b"b_oneof_2", "bool", b"bool", "inner_enum_in_oneof", b"inner_enum_in_oneof", "outer_enum_in_oneof", b"outer_enum_in_oneof", "outer_message", b"outer_message", "outer_message_in_oneof", b"outer_message_in_oneof"] 206 | def HasField(self, field_name: _HasFieldArgType) -> builtins.bool: ... 207 | _ClearFieldArgType: typing_extensions.TypeAlias = typing.Literal["OuterEnum", b"OuterEnum", "OuterMessage3", b"OuterMessage3", "_an_optional_string", b"_an_optional_string", "a_oneof", b"a_oneof", "a_oneof_1", b"a_oneof_1", "a_oneof_2", b"a_oneof_2", "a_outer_enum", b"a_outer_enum", "a_repeated_string", b"a_repeated_string", "a_string", b"a_string", "an_optional_string", b"an_optional_string", "b_oneof", b"b_oneof", "b_oneof_1", b"b_oneof_1", "b_oneof_2", b"b_oneof_2", "bool", b"bool", "email", b"email", "email_by_uid", b"email_by_uid", "inner_enum", b"inner_enum", "inner_enum_in_oneof", b"inner_enum_in_oneof", "map_message", b"map_message", "map_scalar", b"map_scalar", "outer_enum_in_oneof", b"outer_enum_in_oneof", "outer_message", b"outer_message", "outer_message_in_oneof", b"outer_message_in_oneof", "user_id", b"user_id"] 208 | def ClearField(self, field_name: _ClearFieldArgType) -> None: ... 209 | _WhichOneofReturnType__an_optional_string: typing_extensions.TypeAlias = typing.Literal["an_optional_string"] 210 | _WhichOneofArgType__an_optional_string: typing_extensions.TypeAlias = typing.Literal["_an_optional_string", b"_an_optional_string"] 211 | _WhichOneofReturnType_a_oneof: typing_extensions.TypeAlias = typing.Literal["a_oneof_1", "a_oneof_2", "outer_message_in_oneof", "outer_enum_in_oneof", "inner_enum_in_oneof"] 212 | _WhichOneofArgType_a_oneof: typing_extensions.TypeAlias = typing.Literal["a_oneof", b"a_oneof"] 213 | _WhichOneofReturnType_b_oneof: typing_extensions.TypeAlias = typing.Literal["b_oneof_1", "b_oneof_2"] 214 | _WhichOneofArgType_b_oneof: typing_extensions.TypeAlias = typing.Literal["b_oneof", b"b_oneof"] 215 | @typing.overload 216 | def WhichOneof(self, oneof_group: _WhichOneofArgType__an_optional_string) -> _WhichOneofReturnType__an_optional_string | None: ... 217 | @typing.overload 218 | def WhichOneof(self, oneof_group: _WhichOneofArgType_a_oneof) -> _WhichOneofReturnType_a_oneof | None: ... 219 | @typing.overload 220 | def WhichOneof(self, oneof_group: _WhichOneofArgType_b_oneof) -> _WhichOneofReturnType_b_oneof | None: ... 221 | 222 | Global___SimpleProto3: typing_extensions.TypeAlias = SimpleProto3 223 | --------------------------------------------------------------------------------