Skip to content

chore: migrate packages from black to ruff - #18135

Draft
daniel-sanche wants to merge 12 commits into
mainfrom
migrate-black-to-ruff-lint
Draft

chore: migrate packages from black to ruff#18135
daniel-sanche wants to merge 12 commits into
mainfrom
migrate-black-to-ruff-lint

Conversation

@daniel-sanche

Copy link
Copy Markdown
Contributor

As part of #18134, we identified a number of packages that are still using black for formatting, inconsistent with the rest of the repo. This PR updates them to use ruff, and re-formats the files

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the linting, import sorting, and formatting toolchain from Black to Ruff across multiple packages, resulting in widespread import reordering and minor formatting adjustments. The review feedback highlights several violations of the repository's style guide regarding localized mocking, specifically where os.path.exists is patched globally in test suites instead of mocking the local module import path. Additionally, an unnecessary parenthesized expression with a trailing comma in test_aws.py was flagged for creating an unused 1-tuple.

) as mock_session:
with (
mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}),
mock.patch("os.path.exists") as mock_exists,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Patching os.path.exists globally violates the repository style guide's localized mocking rule. Instead, mock the local module import path google.auth.transport._mtls_helper.path.exists to ensure mocks are isolated and do not cause global side effects.

Suggested change
mock.patch("os.path.exists") as mock_exists,
mock.patch("google.auth.transport._mtls_helper.path.exists") as mock_exists,
References
  1. Localized Mocking: When mocking standard functions or filesystem checks (like path.exists), mock the local module import path instead of patching builtins globally, ensuring mocks are isolated. (link)

with mock.patch.object(os.path, "exists", return_value=True), mock.patch(
"builtins.open", mock.mock_open()
with (
mock.patch.object(os.path, "exists", return_value=True),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Patching os.path.exists globally via mock.patch.object violates the repository style guide's localized mocking rule. Please mock the local module import path google.auth.transport._mtls_helper.os.path.exists instead to keep the mock isolated.

Suggested change
mock.patch.object(os.path, "exists", return_value=True),
mock.patch("google.auth.transport._mtls_helper.os.path.exists", return_value=True),
References
  1. Localized Mocking: When mocking standard functions or filesystem checks (like path.exists), mock the local module import path instead of patching builtins globally, ensuring mocks are isolated. (link)

"builtins.open", mock.mock_open()
) as mock_open:
with (
mock.patch.object(os.path, "exists", return_value=True),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Patching os.path.exists globally via mock.patch.object violates the repository style guide's localized mocking rule. Please mock the local module import path google.auth.transport._mtls_helper.os.path.exists instead to keep the mock isolated.

Suggested change
mock.patch.object(os.path, "exists", return_value=True),
mock.patch("google.auth.transport._mtls_helper.os.path.exists", return_value=True),
References
  1. Localized Mocking: When mocking standard functions or filesystem checks (like path.exists), mock the local module import path instead of patching builtins globally, ensuring mocks are isolated. (link)

},
),
mock.patch("builtins.open", mock.mock_open(read_data=fake_config_content)),
mock.patch("os.path.exists", return_value=True),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Patching os.path.exists globally violates the repository style guide's localized mocking rule. Please mock the local module import path google.auth.transport._mtls_helper.path.exists instead to ensure mocks are isolated.

Suggested change
mock.patch("os.path.exists", return_value=True),
mock.patch("google.auth.transport._mtls_helper.path.exists", return_value=True),
References
  1. Localized Mocking: When mocking standard functions or filesystem checks (like path.exists), mock the local module import path instead of patching builtins globally, ensuring mocks are isolated. (link)

Comment on lines +774 to +778
(
reformatted_signed_request.get("headers").append(
{"key": "x-goog-cloud-target-resource", "value": AUDIENCE}
),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This parenthesized expression with a trailing comma creates an unused 1-tuple containing None (since list.append returns None). This is unnecessary and confusing. It should be simplified to a direct method call statement.

        reformatted_signed_request.get("headers").append(
            {"key": "x-goog-cloud-target-resource", "value": AUDIENCE}
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant