Skip to content

Commit 293297d

Browse files
Enforce ruff/Pylint Convention rules (PLC) (#10460)
* Apply ruff/Pylint rule PLC0105 PLC0105 `TypeVar` name does not reflect its covariance * Apply ruff/Pylint rule PLC0206 PLC0206 Extracting value from dictionary without calling `.items()` * Apply ruff/Pylint rule PLC1802 PLC1802 `len()` used as condition without comparison * Ignore ruff/Pylint rule PLC2401 PLC2401 Variable name contains a non-ASCII character * Enforce ruff/Pylint Convention rules (PLC)
1 parent 827696b commit 293297d

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ extend-select = [
260260
"PERF", # Perflint
261261
"W", # pycodestyle warnings
262262
"PGH", # pygrep-hooks
263+
"PLC", # Pylint Convention
263264
"PLE", # Pylint Errors
264265
"PLR", # Pylint Refactor
265266
"PLW", # Pylint Warnings
@@ -278,6 +279,8 @@ ignore = [
278279
"PERF203", # try-except within a loop incurs performance overhead
279280
"E402", # module level import not at top of file
280281
"E731", # do not assign a lambda expression, use a def
282+
"PLC0415", # `import` should be at the top-level of a file
283+
"PLC0206", # extracting value from dictionary without calling `.items()`
281284
"PLR091", # too many arguments / branches / statements
282285
"PLR2004", # magic value used in comparison
283286
"PLW0603", # using the global statement to update is discouraged

xarray/core/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def copy(
195195

196196
# Temporary placeholder for indicating an array api compliant type.
197197
# hopefully in the future we can narrow this down more:
198-
T_DuckArray = TypeVar("T_DuckArray", bound=Any, covariant=True)
198+
T_DuckArray = TypeVar("T_DuckArray", bound=Any, covariant=True) # noqa: PLC0105
199199

200200
# For typing pandas extension arrays.
201201
T_ExtensionArray = TypeVar("T_ExtensionArray", bound=pd.api.extensions.ExtensionArray)

xarray/tests/test_dask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ def test_map_blocks_da_ds_with_template(obj):
13721372

13731373
# Check that indexes are written into the graph directly
13741374
dsk = dict(actual.__dask_graph__())
1375-
assert len({k for k in dsk if "x-coordinate" in k})
1375+
assert {k for k in dsk if "x-coordinate" in k}
13761376
assert all(
13771377
isinstance(v, PandasIndex) for k, v in dsk.items() if "x-coordinate" in k
13781378
)

xarray/tests/test_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ def test_chunk_by_frequency(self, freq: str, calendar: str, add_gap: bool) -> No
12141214
import dask.array
12151215

12161216
N = 365 * 2
1217-
ΔN = 28
1217+
ΔN = 28 # noqa: PLC2401
12181218
time = xr.date_range(
12191219
"2001-01-01", periods=N + ΔN, freq="D", calendar=calendar
12201220
).to_numpy(copy=True)

xarray/tests/test_groupby.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,7 @@ def test_groupby_properties(self) -> None:
13211321
grouped = self.da.groupby("abc")
13221322
expected_groups = {"a": range(9), "c": [9], "b": range(10, 20)}
13231323
assert expected_groups.keys() == grouped.groups.keys()
1324-
for key in expected_groups:
1325-
expected_group = expected_groups[key]
1324+
for key, expected_group in expected_groups.items():
13261325
actual_group = grouped.groups[key]
13271326

13281327
# TODO: array_api doesn't allow slice:

xarray/ufuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_array_namespace(*args):
3939
names = [module.__name__ for module in xps]
4040
raise ValueError(f"Mixed array types {names} are not supported.")
4141

42-
return next(iter(xps)) if len(xps) else np
42+
return next(iter(xps)) if xps else np
4343

4444

4545
class _ufunc_wrapper(ABC):

0 commit comments

Comments
 (0)