Skip to content

Commit eb93894

Browse files
committed
chore: lint
1 parent 06bf824 commit eb93894

17 files changed

Lines changed: 50 additions & 26 deletions

packages/proto-plus/.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ ignore =
66
# Line over-indented for visual indent.
77
# This works poorly with type annotations in method declarations.
88
E128, E131
9+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2333):
10+
# Resolve flake8 lint issues
11+
E203, E231, E266, E501, W503

packages/proto-plus/noxfile.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
import pathlib
1919

2020

21+
BLACK_VERSION = "black[jupyter]==23.7.0"
22+
ISORT_VERSION = "isort==5.11.0"
23+
24+
LINT_PATHS = ["docs", "proto", "tests", "noxfile.py", "setup.py"]
25+
2126
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
2227

23-
DEFAULT_PYTHON_VERSION="3.14"
28+
DEFAULT_PYTHON_VERSION = "3.14"
2429

2530
PYTHON_VERSIONS = [
2631
"3.7",
@@ -42,6 +47,16 @@
4247
def unit(session, implementation):
4348
"""Run the unit test suite."""
4449

50+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
51+
# Remove this check once support for Protobuf 3.x is dropped.
52+
if implementation == "cpp" and session.python in (
53+
"3.11",
54+
"3.12",
55+
"3.13",
56+
"3.14",
57+
):
58+
session.skip("cpp implementation is not supported in python 3.11+")
59+
4560
constraints_path = str(
4661
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
4762
)
@@ -178,4 +193,21 @@ def mypy(session):
178193

179194
# TODO(https://github.com/googleapis/google-cloud-python/issues/15104):
180195
# Enable mypy once this bug is fixed.
181-
session.skip("Skip mypy since this library doesn't have py.typed")
196+
session.skip("Skip mypy since this library doesn't have py.typed")
197+
198+
199+
@nox.session(python=DEFAULT_PYTHON_VERSION)
200+
def lint(session):
201+
"""Run linters.
202+
203+
Returns a failure if the linters find linting errors or sufficiently
204+
serious code quality issues.
205+
"""
206+
session.install("flake8", BLACK_VERSION)
207+
session.run(
208+
"black",
209+
"--check",
210+
*LINT_PATHS,
211+
)
212+
213+
session.run("flake8", "proto", "tests")

packages/proto-plus/proto/datetime_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
"""Helpers for :mod:`datetime`."""
1616

17-
import calendar
1817
import datetime
1918
import re
2019

packages/proto-plus/proto/marshal/collections/maps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import collections
1616

1717
from proto.utils import cached_property
18-
from google.protobuf.message import Message
1918

2019

2120
class MapComposite(collections.abc.MutableMapping):

packages/proto-plus/proto/marshal/marshal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# limitations under the License.
1414

1515
import abc
16-
import enum
1716

18-
from google.protobuf import message
1917
from google.protobuf import duration_pb2
2018
from google.protobuf import timestamp_pb2
2119
from google.protobuf import field_mask_pb2

packages/proto-plus/proto/marshal/rules/dates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
from datetime import datetime
1616
from datetime import timedelta
17-
from datetime import timezone
1817

1918
from google.protobuf import duration_pb2
2019
from google.protobuf import timestamp_pb2
21-
from proto import datetime_helpers, utils
20+
from proto import datetime_helpers
2221

2322

2423
class TimestampRule:

packages/proto-plus/proto/marshal/rules/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def to_proto(self, value):
3434
try:
3535
# Try the fast path first.
3636
return self._descriptor(**value)
37-
except (TypeError, ValueError, AttributeError) as ex:
37+
except (TypeError, ValueError, AttributeError):
3838
# If we have a TypeError, ValueError or AttributeError,
3939
# try the slow path in case the error
4040
# was:

packages/proto-plus/proto/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
def has_upb():
1919
try:
20-
from google._upb import _message # pylint: disable=unused-import
20+
from google._upb import _message # noqa: F401
2121

2222
has_upb = True
2323
except ImportError:

packages/proto-plus/tests/test_fields_bytes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import base64
16-
import pytest
1716

1817
import proto
1918

@@ -79,7 +78,7 @@ class Foo(proto.Message):
7978
# converting a proto message to a dict base64 encodes the bytes
8079
# because it may be sent over the network via a protocol like HTTP.
8180
encoded_swallow: str = base64.urlsafe_b64encode(b"unladen swallow").decode("utf-8")
82-
assert type(encoded_swallow) == str
81+
assert type(encoded_swallow) is str
8382
foo.baz = encoded_swallow
8483
assert foo.baz == b"unladen swallow"
8584

packages/proto-plus/tests/test_fields_optional.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ class Squid(proto.Message):
2626

2727
assert Squid.mass_kg in squid_1
2828
assert squid_1.mass_kg == 20
29-
assert not Squid.mass_kg in squid_2
29+
assert Squid.mass_kg not in squid_2
3030

3131
squid_2.mass_kg = 30
3232
assert squid_2.mass_kg == 30
3333
assert Squid.mass_kg in squid_2
3434

3535
del squid_1.mass_kg
36-
assert not Squid.mass_kg in squid_1
36+
assert Squid.mass_kg not in squid_1
3737

3838
with pytest.raises(AttributeError):
3939
Squid.shell
@@ -53,7 +53,7 @@ class Squid(proto.Message):
5353
s = Squid(mass_kg=20)
5454
assert s.mass_kg == 20
5555
assert not s.mass_lbs
56-
assert not Squid.iridiphore_num in s
56+
assert Squid.iridiphore_num not in s
5757

5858
s.iridiphore_num = 600
5959
assert s.mass_kg == 20
@@ -76,7 +76,7 @@ class Clam(proto.Message):
7676

7777
assert c.mass_kg == 20
7878
assert not c.mass_lbs
79-
assert not Clam.flute_radius in c
79+
assert Clam.flute_radius not in c
8080
c.flute_radius = 30
8181
assert c.mass_kg == 20
8282
assert not c.mass_lbs

0 commit comments

Comments
 (0)