Skip to content

Enforce ruff/Pylint Refactor rules (PLR) #10459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply ruff/Pylint rule PLR5501
PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
  • Loading branch information
DimitriPapadopoulos committed Jun 28, 2025
commit b34c22a9eafc9348e967a6ea16df0616c6ebfe8e
17 changes: 8 additions & 9 deletions xarray/coding/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ def validate_char_dim_name(strlen, encoding, name) -> str:
"To silence this warning either remove 'char_dim_name' from encoding or provide a fitting name."
)
char_dim_name = f"{new_dim_name}{strlen}"
else:
if (
original_shape := encoding.get("original_shape", [-1])[-1]
) != -1 and original_shape != strlen:
emit_user_level_warning(
f"String dimension length mismatch on variable {name!r}. '{original_shape}' provided by encoding, but data has length of '{strlen}'. Using '{char_dim_name}{strlen}' instead of {char_dim_name!r} to prevent possible naming clash.\n"
f"To silence this warning remove 'original_shape' from encoding."
)
char_dim_name = f"{char_dim_name}{strlen}"
elif (
Copy link
Contributor

Choose a reason for hiding this comment

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

@DimitriPapadopoulos Great to see this applied to the code base. One question, will this also be detected during pre-commit now?

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Jun 28, 2025

Choose a reason for hiding this comment

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

Yes, pre-commit runs ruff, which reads its configuration from pyproject.toml as usual.

original_shape := encoding.get("original_shape", [-1])[-1]
) != -1 and original_shape != strlen:
emit_user_level_warning(
f"String dimension length mismatch on variable {name!r}. '{original_shape}' provided by encoding, but data has length of '{strlen}'. Using '{char_dim_name}{strlen}' instead of {char_dim_name!r} to prevent possible naming clash.\n"
f"To silence this warning remove 'original_shape' from encoding."
)
char_dim_name = f"{char_dim_name}{strlen}"
else:
char_dim_name = f"string{strlen}"

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy