diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b69df0..84082d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.9.1 hooks: - id: ruff-format args: ["--diff", "src", "tests"] diff --git a/poetry.lock b/poetry.lock index f80a555..3742268 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1825,30 +1825,30 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.7.4" +version = "0.9.1" description = "An extremely fast Python linter and code formatter, written in Rust." optional = true python-versions = ">=3.7" groups = ["main"] files = [ - {file = "ruff-0.7.4-py3-none-linux_armv6l.whl", hash = "sha256:a4919925e7684a3f18e18243cd6bea7cfb8e968a6eaa8437971f681b7ec51478"}, - {file = "ruff-0.7.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:cfb365c135b830778dda8c04fb7d4280ed0b984e1aec27f574445231e20d6c63"}, - {file = "ruff-0.7.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:63a569b36bc66fbadec5beaa539dd81e0527cb258b94e29e0531ce41bacc1f20"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0d06218747d361d06fd2fdac734e7fa92df36df93035db3dc2ad7aa9852cb109"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e0cea28d0944f74ebc33e9f934238f15c758841f9f5edd180b5315c203293452"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:80094ecd4793c68b2571b128f91754d60f692d64bc0d7272ec9197fdd09bf9ea"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:997512325c6620d1c4c2b15db49ef59543ef9cd0f4aa8065ec2ae5103cedc7e7"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00b4cf3a6b5fad6d1a66e7574d78956bbd09abfd6c8a997798f01f5da3d46a05"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7dbdc7d8274e1422722933d1edddfdc65b4336abf0b16dfcb9dedd6e6a517d06"}, - {file = "ruff-0.7.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e92dfb5f00eaedb1501b2f906ccabfd67b2355bdf117fea9719fc99ac2145bc"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3bd726099f277d735dc38900b6a8d6cf070f80828877941983a57bca1cd92172"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2e32829c429dd081ee5ba39aef436603e5b22335c3d3fff013cd585806a6486a"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:662a63b4971807623f6f90c1fb664613f67cc182dc4d991471c23c541fee62dd"}, - {file = "ruff-0.7.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:876f5e09eaae3eb76814c1d3b68879891d6fde4824c015d48e7a7da4cf066a3a"}, - {file = "ruff-0.7.4-py3-none-win32.whl", hash = "sha256:75c53f54904be42dd52a548728a5b572344b50d9b2873d13a3f8c5e3b91f5cac"}, - {file = "ruff-0.7.4-py3-none-win_amd64.whl", hash = "sha256:745775c7b39f914238ed1f1b0bebed0b9155a17cd8bc0b08d3c87e4703b990d6"}, - {file = "ruff-0.7.4-py3-none-win_arm64.whl", hash = "sha256:11bff065102c3ae9d3ea4dc9ecdfe5a5171349cdd0787c1fc64761212fc9cf1f"}, - {file = "ruff-0.7.4.tar.gz", hash = "sha256:cd12e35031f5af6b9b93715d8c4f40360070b2041f81273d0527683d5708fce2"}, + {file = "ruff-0.9.1-py3-none-linux_armv6l.whl", hash = "sha256:84330dda7abcc270e6055551aca93fdde1b0685fc4fd358f26410f9349cf1743"}, + {file = "ruff-0.9.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3cae39ba5d137054b0e5b472aee3b78a7c884e61591b100aeb544bcd1fc38d4f"}, + {file = "ruff-0.9.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:50c647ff96f4ba288db0ad87048257753733763b409b2faf2ea78b45c8bb7fcb"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f0c8b149e9c7353cace7d698e1656ffcf1e36e50f8ea3b5d5f7f87ff9986a7ca"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:beb3298604540c884d8b282fe7625651378e1986c25df51dec5b2f60cafc31ce"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:39d0174ccc45c439093971cc06ed3ac4dc545f5e8bdacf9f067adf879544d969"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:69572926c0f0c9912288915214ca9b2809525ea263603370b9e00bed2ba56dbd"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:937267afce0c9170d6d29f01fcd1f4378172dec6760a9f4dface48cdabf9610a"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:186c2313de946f2c22bdf5954b8dd083e124bcfb685732cfb0beae0c47233d9b"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f94942a3bb767675d9a051867c036655fe9f6c8a491539156a6f7e6b5f31831"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:728d791b769cc28c05f12c280f99e8896932e9833fef1dd8756a6af2261fd1ab"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2f312c86fb40c5c02b44a29a750ee3b21002bd813b5233facdaf63a51d9a85e1"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:ae017c3a29bee341ba584f3823f805abbe5fe9cd97f87ed07ecbf533c4c88366"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5dc40a378a0e21b4cfe2b8a0f1812a6572fc7b230ef12cd9fac9161aa91d807f"}, + {file = "ruff-0.9.1-py3-none-win32.whl", hash = "sha256:46ebf5cc106cf7e7378ca3c28ce4293b61b449cd121b98699be727d40b79ba72"}, + {file = "ruff-0.9.1-py3-none-win_amd64.whl", hash = "sha256:342a824b46ddbcdddd3abfbb332fa7fcaac5488bf18073e841236aadf4ad5c19"}, + {file = "ruff-0.9.1-py3-none-win_arm64.whl", hash = "sha256:1cd76c7f9c679e6e8f2af8f778367dca82b95009bc7b1a85a47f1521ae524fa7"}, + {file = "ruff-0.9.1.tar.gz", hash = "sha256:fd2b25ecaf907d6458fa842675382c8597b3c746a2dde6717fe3415425df0c17"}, ] [[package]] @@ -2256,4 +2256,4 @@ rust-codec = ["betterproto-rust-codec"] [metadata] lock-version = "2.1" python-versions = ">=3.9,<4.0" -content-hash = "8803a27b9a438cf868b4881dc73e77bd8dddb88cae665ab6a90a9cc063ad4150" +content-hash = "cf90b82485ce6837f190477b98778fedc112e9efb6b0dde487da9d65cd92db3b" diff --git a/pyproject.toml b/pyproject.toml index b50af77..7b1b6e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ dynamic = ["dependencies"] [tool.poetry.dependencies] # The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml -ruff = { version = "~0.7.4", optional = true } +ruff = { version = "~0.9.1", optional = true } grpclib = "^0.4.1" jinja2 = { version = ">=3.0.3", optional = true } python-dateutil = "^2.8" diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index 7ed3785..ce8a26a 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -2011,10 +2011,10 @@ class _Timestamp(Timestamp): return f"{result}Z" if (nanos % 1e6) == 0: # Serialize 3 fractional digits. - return f"{result}.{int(nanos // 1e6) :03d}Z" + return f"{result}.{int(nanos // 1e6):03d}Z" if (nanos % 1e3) == 0: # Serialize 6 fractional digits. - return f"{result}.{int(nanos // 1e3) :06d}Z" + return f"{result}.{int(nanos // 1e3):06d}Z" # Serialize 9 fractional digits. return f"{result}.{nanos:09d}" diff --git a/tests/grpc/test_grpclib_client.py b/tests/grpc/test_grpclib_client.py index f64351c..b9eb559 100644 --- a/tests/grpc/test_grpclib_client.py +++ b/tests/grpc/test_grpclib_client.py @@ -26,12 +26,12 @@ async def _test_client(client: ThingServiceClient, name="clean room", **kwargs): def _assert_request_meta_received(deadline, metadata): def server_side_test(stream): - assert stream.deadline._timestamp == pytest.approx( - deadline._timestamp, 1 - ), "The provided deadline should be received serverside" - assert ( - stream.metadata["authorization"] == metadata["authorization"] - ), "The provided authorization metadata should be received serverside" + assert stream.deadline._timestamp == pytest.approx(deadline._timestamp, 1), ( + "The provided deadline should be received serverside" + ) + assert stream.metadata["authorization"] == metadata["authorization"], ( + "The provided authorization metadata should be received serverside" + ) return server_side_test @@ -265,9 +265,9 @@ async def test_async_gen_for_stream_stream_request(): else: # No more things to send make sure channel is closed request_chan.close() - assert response_index == len( - expected_things - ), "Didn't receive all expected responses" + assert response_index == len(expected_things), ( + "Didn't receive all expected responses" + ) @pytest.mark.asyncio diff --git a/tests/inputs/casing/test_casing.py b/tests/inputs/casing/test_casing.py index 9ca4243..b050043 100644 --- a/tests/inputs/casing/test_casing.py +++ b/tests/inputs/casing/test_casing.py @@ -4,20 +4,20 @@ from tests.output_betterproto.casing import Test def test_message_attributes(): message = Test() - assert hasattr( - message, "snake_case_message" - ), "snake_case field name is same in python" + assert hasattr(message, "snake_case_message"), ( + "snake_case field name is same in python" + ) assert hasattr(message, "camel_case"), "CamelCase field is snake_case in python" assert hasattr(message, "uppercase"), "UPPERCASE field is lowercase in python" def test_message_casing(): - assert hasattr( - casing, "SnakeCaseMessage" - ), "snake_case Message name is converted to CamelCase in python" + assert hasattr(casing, "SnakeCaseMessage"), ( + "snake_case Message name is converted to CamelCase in python" + ) def test_enum_casing(): - assert hasattr( - casing, "MyEnum" - ), "snake_case Enum name is converted to CamelCase in python" + assert hasattr(casing, "MyEnum"), ( + "snake_case Enum name is converted to CamelCase in python" + ) diff --git a/tests/inputs/casing_inner_class/test_casing_inner_class.py b/tests/inputs/casing_inner_class/test_casing_inner_class.py index 267b105..466b532 100644 --- a/tests/inputs/casing_inner_class/test_casing_inner_class.py +++ b/tests/inputs/casing_inner_class/test_casing_inner_class.py @@ -2,13 +2,13 @@ import tests.output_betterproto.casing_inner_class as casing_inner_class def test_message_casing_inner_class_name(): - assert hasattr( - casing_inner_class, "TestInnerClass" - ), "Inline defined Message is correctly converted to CamelCase" + assert hasattr(casing_inner_class, "TestInnerClass"), ( + "Inline defined Message is correctly converted to CamelCase" + ) def test_message_casing_inner_class_attributes(): message = casing_inner_class.Test() - assert hasattr( - message.inner, "old_exp" - ), "Inline defined Message attribute is snake_case" + assert hasattr(message.inner, "old_exp"), ( + "Inline defined Message attribute is snake_case" + ) diff --git a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py index 2b32b53..c1a973c 100644 --- a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py +++ b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.py @@ -3,12 +3,12 @@ from tests.output_betterproto.casing_message_field_uppercase import Test def test_message_casing(): message = Test() - assert hasattr( - message, "uppercase" - ), "UPPERCASE attribute is converted to 'uppercase' in python" - assert hasattr( - message, "uppercase_v2" - ), "UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python" - assert hasattr( - message, "upper_camel_case" - ), "UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python" + assert hasattr(message, "uppercase"), ( + "UPPERCASE attribute is converted to 'uppercase' in python" + ) + assert hasattr(message, "uppercase_v2"), ( + "UPPERCASE_V2 attribute is converted to 'uppercase_v2' in python" + ) + assert hasattr(message, "upper_camel_case"), ( + "UPPER_CAMEL_CASE attribute is converted to upper_camel_case in python" + ) diff --git a/tests/inputs/enum/test_enum.py b/tests/inputs/enum/test_enum.py index 21a5ac3..0663bea 100644 --- a/tests/inputs/enum/test_enum.py +++ b/tests/inputs/enum/test_enum.py @@ -27,9 +27,9 @@ def test_enum_is_comparable_with_int(): def test_enum_to_dict(): - assert ( - "choice" not in Test(choice=Choice.ZERO).to_dict() - ), "Default enum value is not serialized" + assert "choice" not in Test(choice=Choice.ZERO).to_dict(), ( + "Default enum value is not serialized" + ) assert ( Test(choice=Choice.ZERO).to_dict(include_default_values=True)["choice"] == "ZERO" diff --git a/tests/test_get_ref_type.py b/tests/test_get_ref_type.py index 7b529bd..2179662 100644 --- a/tests/test_get_ref_type.py +++ b/tests/test_get_ref_type.py @@ -56,9 +56,9 @@ def test_reference_google_wellknown_types_non_wrappers( ) assert name == expected_name - assert imports.__contains__( - expected_import - ), f"{expected_import} not found in {imports}" + assert imports.__contains__(expected_import), ( + f"{expected_import} not found in {imports}" + ) @pytest.mark.parametrize( @@ -102,9 +102,9 @@ def test_reference_google_wellknown_types_non_wrappers_pydantic( ) assert name == expected_name - assert imports.__contains__( - expected_import - ), f"{expected_import} not found in {imports}" + assert imports.__contains__(expected_import), ( + f"{expected_import} not found in {imports}" + ) @pytest.mark.parametrize( diff --git a/tests/test_version.py b/tests/test_version.py index 0a6ca6c..09bc115 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -11,6 +11,6 @@ PROJECT_TOML = Path(__file__).joinpath("..", "..", "pyproject.toml").resolve() def test_version(): with PROJECT_TOML.open() as toml_file: project_config = tomlkit.loads(toml_file.read()) - assert ( - __version__ == project_config["project"]["version"] - ), "Project version should match in package and package config" + assert __version__ == project_config["project"]["version"], ( + "Project version should match in package and package config" + )