Skip to content

Commit 05b61a5

Browse files
committed
Use Pylint to lint gRPC Python examples
1 parent 97453a3 commit 05b61a5

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

.pylintrc-examples

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
[MASTER]
2+
ignore=
3+
src/python/grpcio/grpc/beta,
4+
src/python/grpcio/grpc/framework,
5+
src/python/grpcio/grpc/framework/common,
6+
src/python/grpcio/grpc/framework/foundation,
7+
src/python/grpcio/grpc/framework/interfaces,
8+
9+
[VARIABLES]
10+
11+
# TODO(https://github.com/PyCQA/pylint/issues/1345): How does the inspection
12+
# not include "unused_" and "ignored_" by default?
13+
dummy-variables-rgx=^ignored_|^unused_
14+
15+
[DESIGN]
16+
17+
# NOTE(nathaniel): Not particularly attached to this value; it just seems to
18+
# be what works for us at the moment (excepting the dead-code-walking Beta
19+
# API).
20+
max-args=6
21+
22+
[MISCELLANEOUS]
23+
24+
# NOTE(nathaniel): We are big fans of "TODO(<issue link>): " and
25+
# "NOTE(<username or issue link>): ". We do not allow "TODO:",
26+
# "TODO(<username>):", "FIXME:", or anything else.
27+
notes=FIXME,XXX
28+
29+
[MESSAGES CONTROL]
30+
31+
disable=
32+
# -- START OF EXAMPLE-SPECIFIC SUPPRESSIONS --
33+
no-self-use,
34+
unused-argument,
35+
unused-variable,
36+
# -- END OF EXAMPLE-SPECIFIC SUPPRESSIONS --
37+
38+
# TODO(https://github.com/PyCQA/pylint/issues/59#issuecomment-283774279):
39+
# Enable cyclic-import after a 1.7-or-later pylint release that
40+
# recognizes our disable=cyclic-import suppressions.
41+
cyclic-import,
42+
# TODO(https://github.com/grpc/grpc/issues/8622): Enable this after the
43+
# Beta API is removed.
44+
duplicate-code,
45+
# TODO(https://github.com/grpc/grpc/issues/261): Doesn't seem to
46+
# understand enum and concurrent.futures; look into this later with the
47+
# latest pylint version.
48+
import-error,
49+
# TODO(https://github.com/grpc/grpc/issues/261): Enable this one.
50+
# Should take a little configuration but not much.
51+
invalid-name,
52+
# TODO(https://github.com/grpc/grpc/issues/261): This doesn't seem to
53+
# work for now? Try with a later pylint?
54+
locally-disabled,
55+
# NOTE(nathaniel): What even is this? *Enabling* an inspection results
56+
# in a warning? How does that encourage more analysis and coverage?
57+
locally-enabled,
58+
# NOTE(nathaniel): We don't write doc strings for most private code
59+
# elements.
60+
missing-docstring,
61+
# NOTE(nathaniel): In numeric comparisons it is better to have the
62+
# lesser (or lesser-or-equal-to) quantity on the left when the
63+
# expression is true than it is to worry about which is an identifier
64+
# and which a literal value.
65+
misplaced-comparison-constant,
66+
# NOTE(nathaniel): Our completely abstract interface classes don't have
67+
# constructors.
68+
no-init,
69+
# TODO(https://github.com/grpc/grpc/issues/261): Doesn't yet play
70+
# nicely with some of our code being implemented in Cython. Maybe in a
71+
# later version?
72+
no-name-in-module,
73+
# TODO(https://github.com/grpc/grpc/issues/261): Suppress these where
74+
# the odd shape of the authentication portion of the API forces them on
75+
# us and enable everywhere else.
76+
protected-access,
77+
# NOTE(nathaniel): Pylint and I will probably never agree on this.
78+
too-few-public-methods,
79+
# NOTE(nathaniel): Pylint and I wil probably never agree on this for
80+
# private classes. For public classes maybe?
81+
too-many-instance-attributes,
82+
# NOTE(nathaniel): Some of our modules have a lot of lines... of
83+
# specification and documentation. Maybe if this were
84+
# lines-of-code-based we would use it.
85+
too-many-lines,
86+
# TODO(https://github.com/grpc/grpc/issues/261): Maybe we could have
87+
# this one if we extracted just a few more helper functions...
88+
too-many-nested-blocks,
89+
# TODO(https://github.com/grpc/grpc/issues/261): Disable unnecessary
90+
# super-init requirement for abstract class implementations for now.
91+
super-init-not-called,
92+
# NOTE(nathaniel): A single statement that always returns program
93+
# control is better than two statements the first of which sometimes
94+
# returns program control and the second of which always returns
95+
# program control. Probably generally, but definitely in the cases of
96+
# if:/else: and for:/else:.
97+
useless-else-on-loop,
98+
no-else-return,
99+
# NOTE(lidiz): Python 3 make object inheritance default, but not PY2
100+
useless-object-inheritance,

examples/python/helloworld/greeter_client_with_options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""The Python implementation of the GRPC helloworld.Greeter client with channel options and call timeout parameters."""
14+
"""gRPC Python helloworld.Greeter client with channel options and call timeout parameters."""
1515

1616
from __future__ import print_function
1717
import logging

tools/distrib/pylint_code.sh

+6
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@ for dir in "${TEST_DIRS[@]}"; do
4848
$PYTHON -m pylint --rcfile=.pylintrc-tests -rn "$dir" || EXIT=1
4949
done
5050

51+
find examples/python \
52+
-iname "*.py" \
53+
-not -name "*_pb2.py" \
54+
-not -name "*_pb2_grpc.py" \
55+
| xargs $PYTHON -m pylint --rcfile=.pylintrc-examples -rn
56+
5157
exit $EXIT

0 commit comments

Comments
 (0)