Skip to content

Commit 44d3a05

Browse files
authored
Set up typechecking in this repo. (#22)
1 parent fbf4bdd commit 44d3a05

File tree

6 files changed

+58
-44
lines changed

6 files changed

+58
-44
lines changed

.github/workflows/pants.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ jobs:
5858
pants --version
5959
- name: Check BUILD files
6060
run: pants tailor --check update-build-files --check '::'
61-
- name: Lint and test
61+
- name: Lint, typecheck and test
6262
run: |
63-
pants lint test ::
63+
pants lint check test ::
6464
- name: Upload Pants log
6565
uses: actions/upload-artifact@v3
6666
with:

3rdparty/python/default.lock

+37-42
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
//
55
// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
66
// {
7-
// "version": 2,
7+
// "version": 3,
88
// "valid_for_interpreter_constraints": [
99
// "CPython<3.11,>=3.8"
1010
// ],
1111
// "generated_with_requirements": [
1212
// "protobuf==3.20.1",
13-
// "thrift==0.15.0"
14-
// ]
13+
// "thrift==0.15.0",
14+
// "types-protobuf==3.20.1"
15+
// ],
16+
// "manylinux": "manylinux2014",
17+
// "requirement_constraints": [],
18+
// "only_binary": [],
19+
// "no_binary": []
1520
// }
1621
// --- END PANTS LOCKFILE METADATA ---
1722

@@ -31,11 +36,6 @@
3136
"hash": "adfc6cf69c7f8c50fd24c793964eef18f0ac321315439d94945820612849c388",
3237
"url": "https://files.pythonhosted.org/packages/ef/c8/2e7f7feaf804b7206e6cc8fa3f0f49834a78f7cb127813d2c45e42d5f7bf/protobuf-3.20.1-py2.py3-none-any.whl"
3338
},
34-
{
35-
"algorithm": "sha256",
36-
"hash": "7e371f10abe57cee5021797126c93479f59fccc9693dafd6bd5633ab67808a91",
37-
"url": "https://files.pythonhosted.org/packages/00/f6/061b2d6ae57c458dbd37df4edb667872f65001a124a7023cd7bced76c09a/protobuf-3.20.1-cp39-cp39-win_amd64.whl"
38-
},
3939
{
4040
"algorithm": "sha256",
4141
"hash": "6f50601512a3d23625d8a85b1638d914a0970f17920ff39cec63aaef80a93fb7",
@@ -46,11 +46,6 @@
4646
"hash": "adc31566d027f45efe3f44eeb5b1f329da43891634d61c75a5944e9be6dd42c9",
4747
"url": "https://files.pythonhosted.org/packages/19/96/1283259c25bc48a6df98fa096f66fc568b40137b93806ef5ff66a2d166b1/protobuf-3.20.1.tar.gz"
4848
},
49-
{
50-
"algorithm": "sha256",
51-
"hash": "dd5789b2948ca702c17027c84c2accb552fc30f4622a98ab5c51fcfe8c50d3e7",
52-
"url": "https://files.pythonhosted.org/packages/3c/59/b0ac614cdb5e73d3a7171e3de8d9cf933cc76068305b13ac9351c9985835/protobuf-3.20.1-cp38-cp38-win32.whl"
53-
},
5449
{
5550
"algorithm": "sha256",
5651
"hash": "cd68be2559e2a3b84f517fb029ee611546f7812b1fdd0aa2ecc9bc6ec0e4fdde",
@@ -66,16 +61,6 @@
6661
"hash": "cb29edb9eab15742d791e1025dd7b6a8f6fcb53802ad2f6e3adcb102051063ab",
6762
"url": "https://files.pythonhosted.org/packages/7b/4b/12c4959e2065a567acb6c632cfbf97cd12e0e5a48d3d267cb034249588bb/protobuf-3.20.1-cp38-cp38-manylinux2014_aarch64.whl"
6863
},
69-
{
70-
"algorithm": "sha256",
71-
"hash": "9016d01c91e8e625141d24ec1b20fed584703e527d28512aa8c8707f105a683c",
72-
"url": "https://files.pythonhosted.org/packages/89/1a/b4d72e1d7134ffac2156d1dfc3b9ddb21d1664ff392e1e5fe2882a117f81/protobuf-3.20.1-cp310-cp310-win32.whl"
73-
},
74-
{
75-
"algorithm": "sha256",
76-
"hash": "db977c4ca738dd9ce508557d4fce0f5aebd105e158c725beec86feb1f6bc20d8",
77-
"url": "https://files.pythonhosted.org/packages/8f/cd/d2a90e55397acae08363e26db3a1bbd6674c16a891ab8ee033b44e59af09/protobuf-3.20.1-cp39-cp39-win32.whl"
78-
},
7964
{
8065
"algorithm": "sha256",
8166
"hash": "7403941f6d0992d40161aa8bb23e12575637008a5a02283a930addc0508982f9",
@@ -96,20 +81,10 @@
9681
"hash": "06059eb6953ff01e56a25cd02cca1a9649a75a7e65397b5b9b4e929ed71d10cf",
9782
"url": "https://files.pythonhosted.org/packages/bf/2a/8924d1fbdf6cec34e9e58ee84b2a8bbdb2b58730c4cfab5a29934977ea6d/protobuf-3.20.1-cp38-cp38-macosx_10_9_x86_64.whl"
9883
},
99-
{
100-
"algorithm": "sha256",
101-
"hash": "32ca378605b41fd180dfe4e14d3226386d8d1b002ab31c969c366549e66a2bb7",
102-
"url": "https://files.pythonhosted.org/packages/c0/9c/bb88091287418ae1cf8af2bb9ed9710748a562b9abc227e4884d687a8650/protobuf-3.20.1-cp310-cp310-win_amd64.whl"
103-
},
10484
{
10585
"algorithm": "sha256",
10686
"hash": "69ccfdf3657ba59569c64295b7d51325f91af586f8d5793b734260dfe2e94e2c",
10787
"url": "https://files.pythonhosted.org/packages/c1/4d/1d46234fbdff4ee05cb7ec6cb6ea9282769fa9fefd72d93de4b85fd3d8c4/protobuf-3.20.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl"
108-
},
109-
{
110-
"algorithm": "sha256",
111-
"hash": "77053d28427a29987ca9caf7b72ccafee011257561259faba8dd308fda9a8739",
112-
"url": "https://files.pythonhosted.org/packages/e4/5e/381d134b6c9484d6d80dcace24dd3e0cc165d89b800b162fc52b4ac6941a/protobuf-3.20.1-cp38-cp38-win_amd64.whl"
11388
}
11489
],
11590
"project_name": "protobuf",
@@ -133,7 +108,7 @@
133108
"project_name": "six",
134109
"requires_dists": [],
135110
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7",
136-
"version": "1.16"
111+
"version": "1.16.0"
137112
},
138113
{
139114
"artifacts": [
@@ -152,28 +127,48 @@
152127
"twisted; extra == \"twisted\""
153128
],
154129
"requires_python": null,
155-
"version": "0.15"
130+
"version": "0.15.0"
131+
},
132+
{
133+
"artifacts": [
134+
{
135+
"algorithm": "sha256",
136+
"hash": "b0bc0ffde2a339ee25c4b47e9dd515010153ad80c21d16fb57a2429987579801",
137+
"url": "https://files.pythonhosted.org/packages/94/0f/bc26638706bfc4b3a7b6a0aa0357b66d30ff332cc6c378b8ddc85bc41f9a/types_protobuf-3.20.1-py3-none-any.whl"
138+
},
139+
{
140+
"algorithm": "sha256",
141+
"hash": "36e3426476e373da6f2bb8a81a1194478cd1f33813a4e254849146d28c450e00",
142+
"url": "https://files.pythonhosted.org/packages/7d/3c/d22e8e1767d1525366970f3013ab1b614ca203d6e5ecfea977b0cf0952e3/types-protobuf-3.20.1.tar.gz"
143+
}
144+
],
145+
"project_name": "types-protobuf",
146+
"requires_dists": [],
147+
"requires_python": null,
148+
"version": "3.20.1"
156149
}
157150
],
158-
"platform_tag": [
159-
"cp39",
160-
"cp39",
161-
"macosx_12_0_arm64"
162-
]
151+
"platform_tag": null
163152
}
164153
],
165154
"path_mappings": {},
166-
"pex_version": "2.1.90",
155+
"pex_version": "2.1.134",
156+
"pip_version": "20.3.4-patched",
167157
"prefer_older_binary": false,
168158
"requirements": [
169159
"protobuf==3.20.1",
170-
"thrift==0.15.0"
160+
"thrift==0.15.0",
161+
"types-protobuf==3.20.1"
171162
],
172163
"requires_python": [
173164
"<3.11,>=3.8"
174165
],
175166
"resolver_version": "pip-2020-resolver",
176167
"style": "universal",
168+
"target_systems": [
169+
"linux",
170+
"mac"
171+
],
177172
"transitive": true,
178173
"use_pep517": null
179174
}

3rdparty/python/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
protobuf==3.20.1
22
thrift==0.15.0
3+
types-protobuf==3.20.1

mypy.ini

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[mypy]
2+
3+
# The `gen` identifies thrift-generated files, which we don't want to typecheck.
4+
# Unfortunately this means that mypy may be missing sime type information for the
5+
# generated Python files, which may cause it to falsely ignore errors in code that
6+
# uses the generated code.
7+
#
8+
# But until Thrift supports mypy in a way similar to protobuf (generating stubs for
9+
# your code at codegen time, and providing type stubs for the thrift library)
10+
# this is the best we can do.
11+
[mypy-*.gen.*]
12+
ignore_errors = True

pants.toml

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ backend_packages = [
77
"pants.backend.experimental.codegen.protobuf.go",
88
"pants.backend.experimental.go",
99
"pants.backend.python",
10+
"pants.backend.python.typecheck.mypy",
1011
]
1112

1213
# GOLANG: Remove this line for Go to work. You will also need to have Go installed locally and may
@@ -28,3 +29,6 @@ interpreter_constraints = ["CPython>=3.8,<3.11"]
2829
# `generate-lockfiles` goal for Pants to generate the lockfile for you, although in some
2930
# situations you may need to manually generate it, as explained in the docs.
3031
enable_resolves = true
32+
33+
[python-protobuf]
34+
mypy_plugin = true

src/protobuf/simple_example/v1/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ protobuf_sources(
33
# so that we do not need to add `__init__.py` files to `src/protobuf`. See
44
# https://www.pantsbuild.org/docs/protobuf-python#protobuf-and-source-roots
55
python_source_root="src/python",
6+
# TODO: Infer this. See https://github.com/pantsbuild/pants/issues/19766.
7+
dependencies=["3rdparty/python#types-protobuf"],
68
)

0 commit comments

Comments
 (0)