Skip to content

Commit d946d68

Browse files
Add flags to generate only sync or only async stubs
1 parent e8e1192 commit d946d68

File tree

92 files changed

+5791
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+5791
-83
lines changed

mypy_protobuf/main.py

Lines changed: 184 additions & 82 deletions
Large diffs are not rendered by default.

run_test.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
135135
find proto -name "*.proto" -print0 | xargs -0 "$PROTOC" "${PROTOC_ARGS[@]}" --mypy_out=generate_concrete_servicer_stubs:test/generated-concrete
136136
find proto/testproto/grpc -name "*.proto" -print0 | xargs -0 "$PROTOC" "${PROTOC_ARGS[@]}" --mypy_grpc_out=generate_concrete_servicer_stubs:test/generated-concrete
137137

138+
# Generate with sync_only stubs for testing
139+
find proto/testproto/grpc -name "*.proto" -print0 | xargs -0 "$PROTOC" "${PROTOC_ARGS[@]}" --mypy_grpc_out=only_sync:test/generated-sync-only
140+
141+
# Generate with async_only stubs for testing
142+
find proto/testproto/grpc -name "*.proto" -print0 | xargs -0 "$PROTOC" "${PROTOC_ARGS[@]}" --mypy_grpc_out=only_async:test/generated-async-only
138143

139144
if [[ -n $VALIDATE ]] && ! diff <(echo "$SHA_BEFORE") <(find test/generated -name "*.pyi" -print0 | xargs -0 sha1sum); then
140145
echo -e "${RED}Some .pyi files did not match. Please commit those files${NC}"
@@ -161,6 +166,14 @@ for PY_VER in $PY_VER_UNIT_TESTS; do
161166
CONCRETE_MODULES=( -m test.test_concrete )
162167
MYPYPATH=$MYPYPATH:test/generated-concrete mypy ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --python-executable="$UNIT_TESTS_VENV"/bin/python --python-version="$PY_VER_MYPY_TARGET" "${CONCRETE_MODULES[@]}"
163168

169+
# Run sync_only mypy
170+
SYNC_ONLY_MODULES=( -m test.test_sync_only )
171+
MYPYPATH=$MYPYPATH:test/generated-sync-only mypy ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --python-executable="$UNIT_TESTS_VENV"/bin/python --python-version="$PY_VER_MYPY_TARGET" "${SYNC_ONLY_MODULES[@]}"
172+
173+
# Run async_only mypy
174+
ASYNC_ONLY_MODULES=( -m test.test_async_only )
175+
MYPYPATH=$MYPYPATH:test/generated-async-only mypy ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --python-executable="$UNIT_TESTS_VENV"/bin/python --python-version="$PY_VER_MYPY_TARGET" "${ASYNC_ONLY_MODULES[@]}"
176+
164177
export MYPYPATH=$MYPYPATH:test/generated
165178

166179
# Run mypy
@@ -209,7 +222,7 @@ for PY_VER in $PY_VER_UNIT_TESTS; do
209222
(
210223
# Run unit tests.
211224
source "$UNIT_TESTS_VENV"/bin/activate
212-
PYTHONPATH=test/generated py.test --ignore=test/generated -v
225+
PYTHONPATH=test/generated py.test --ignore=test/generated --ignore=test/generated-sync-only --ignore=test/generated-async-only -v
213226
)
214227
done
215228

test/generated-async-only/__init__.py

Whitespace-only changes.

test/generated-async-only/testproto/Capitalized/Capitalized_pb2.py

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
def ClearField(self, field_name: typing.Literal["a", b"a"]) -> None: ...
31+
32+
Global___lower: typing_extensions.TypeAlias = lower
33+
34+
@typing.final
35+
class Upper(google.protobuf.message.Message):
36+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
37+
38+
LOWER_FIELD_NUMBER: builtins.int
39+
@property
40+
def Lower(self) -> Global___lower: ...
41+
def __init__(
42+
self,
43+
*,
44+
Lower: Global___lower | None = ...,
45+
) -> None: ...
46+
def HasField(self, field_name: typing.Literal["Lower", b"Lower"]) -> builtins.bool: ...
47+
def ClearField(self, field_name: typing.Literal["Lower", b"Lower"]) -> None: ...
48+
49+
Global___Upper: typing_extensions.TypeAlias = Upper
50+
51+
@typing.final
52+
class lower2(google.protobuf.message.Message):
53+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
54+
55+
UPPER_FIELD_NUMBER: builtins.int
56+
@property
57+
def upper(self) -> Global___Upper: ...
58+
def __init__(
59+
self,
60+
*,
61+
upper: Global___Upper | None = ...,
62+
) -> None: ...
63+
def HasField(self, field_name: typing.Literal["upper", b"upper"]) -> builtins.bool: ...
64+
def ClearField(self, field_name: typing.Literal["upper", b"upper"]) -> None: ...
65+
66+
Global___lower2: typing_extensions.TypeAlias = lower2

test/generated-async-only/testproto/Capitalized/__init__.py

Whitespace-only changes.

test/generated-async-only/testproto/__init__.py

Whitespace-only changes.

test/generated-async-only/testproto/comment_special_chars_pb2.py

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
def ClearField(self, field_name: 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"]) -> None: ...
81+
82+
Global___Test: typing_extensions.TypeAlias = Test

test/generated-async-only/testproto/dot/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)