-
-
Notifications
You must be signed in to change notification settings - Fork 150
refactor(ruff): switch from select
to ignore
#1412
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
refactor(ruff): switch from select
to ignore
#1412
Conversation
Maybe we can freeze versions of all type checkers and upgrade manually to prevent this |
tests/extension/decimal/array.py
Outdated
# If the operator is not defined for the underlying objects, | ||
# a TypeError should be raised | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)] | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues, strict=False)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is annoying. strict=False
is the default, so we shouldn't have to specify it. Can you ignore that rule with ruff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/indexes/test_indexes.py
Outdated
check( | ||
assert_type(pd.MultiIndex.from_tuples(zip([1, 2], [3, 4])), pd.MultiIndex), | ||
assert_type( | ||
pd.MultiIndex.from_tuples(zip([1, 2], [3, 4], strict=False)), pd.MultiIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about zip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/series/test_series.py
Outdated
id = [1, 2, 3] | ||
value = ["a", "b", "c"] | ||
df = pd.DataFrame(zip(id, value), columns=["id", "value"]) | ||
df = pd.DataFrame(zip(id, value, strict=False), columns=["id", "value"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about zip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_pandas.py
Outdated
assert_type( | ||
pd.concat(map(lambda _: s2, ["some_value", 3]), axis=1), pd.DataFrame | ||
), | ||
assert_type(pd.concat((s2 for _ in ["some_value", 3]), axis=1), pd.DataFrame), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of this change. I think we explicitly wanted to use map
and lambda
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_pandas.py
Outdated
"B1970": {0: 2.5, 1: 1.2, 2: 0.7}, | ||
"B1980": {0: 3.2, 1: 1.3, 2: 0.1}, | ||
"X": dict(zip(range(3), np.random.randn(3))), | ||
"X": dict(zip(range(3), np.random.randn(3), strict=False)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same zip comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pyproject.toml
Outdated
"PD", # Pandas is here | ||
"PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ | ||
"S101", # https://docs.astral.sh/ruff/rules/assert/ | ||
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can limit this to one file tests/test_io.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pyproject.toml
Outdated
"PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ | ||
"S101", # https://docs.astral.sh/ruff/rules/assert/ | ||
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ | ||
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should aim to fix this one so put it in the second list below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved below
pyproject.toml
Outdated
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ | ||
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ | ||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"ANN", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901", "FIX", "TD", "A001", "PYI042", "ANN201" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIX
andTD
relates toTODO
, so we can do a per-file ignore- Surprised that ANN201 isn't already taken care of because that's the one that requires return types on functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIX
andTD
now more detailedANN201
will be fixed in a separate PR
tests/__init__.py
Outdated
and ... not in tuple_args # fixed-length tuple | ||
and (arr_ndim := getattr(actual, "ndim")) | ||
!= (expected_ndim := len(tuple_args)) | ||
and (arr_ndim := actual.ndim) != (expected_ndim := len(tuple_args)) # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is annoying, because getattr()
is a good usage here. If there is a RUFF rule that is causing this fix, let's ignore it on a per-file basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getattr
is no better than .
, it also raises an error when the attribute is not there. Nevertheless, f251900
tests/__init__.py
Outdated
and isinstance((expected_dtype := dtype_args[0]), type) | ||
and issubclass(expected_dtype, np.generic) | ||
and (arr_dtype := getattr(actual, "dtype")) != expected_dtype | ||
and (arr_dtype := actual.dtype) != expected_dtype # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about doing a per-file ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getattr
is no better than .
, it also raises an error when the attribute is not there. Nevertheless, f251900
We can do it on a per-type-checker basis, and if we see that a new version has these kinds of failures, we can pin it. And report it to them so they are aware. We have pinned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should do those pyrefly
ignores, because they are in disagreement with both mypy
and pyright
.
I also disagree with them reporting the bad-param-name-override
on methods like __getitem__()
and __iter__()
.
We should report this to them, and if we need to, add something in our config to ignore the rules you inserted in the commit #6847e8657878201653b49f401c18b72e680b9eb9 and then put the ignore (for now) in pyproject.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For pyrefly
, I added a TODO in ace7a24
tests/extension/decimal/array.py
Outdated
# If the operator is not defined for the underlying objects, | ||
# a TypeError should be raised | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues)] | ||
res = [op(a, b) for (a, b) in zip(lvalues, rvalues, strict=False)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/indexes/test_indexes.py
Outdated
check( | ||
assert_type(pd.MultiIndex.from_tuples(zip([1, 2], [3, 4])), pd.MultiIndex), | ||
assert_type( | ||
pd.MultiIndex.from_tuples(zip([1, 2], [3, 4], strict=False)), pd.MultiIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/series/test_series.py
Outdated
id = [1, 2, 3] | ||
value = ["a", "b", "c"] | ||
df = pd.DataFrame(zip(id, value), columns=["id", "value"]) | ||
df = pd.DataFrame(zip(id, value, strict=False), columns=["id", "value"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/__init__.py
Outdated
and ... not in tuple_args # fixed-length tuple | ||
and (arr_ndim := getattr(actual, "ndim")) | ||
!= (expected_ndim := len(tuple_args)) | ||
and (arr_ndim := actual.ndim) != (expected_ndim := len(tuple_args)) # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getattr
is no better than .
, it also raises an error when the attribute is not there. Nevertheless, f251900
tests/__init__.py
Outdated
and isinstance((expected_dtype := dtype_args[0]), type) | ||
and issubclass(expected_dtype, np.generic) | ||
and (arr_dtype := getattr(actual, "dtype")) != expected_dtype | ||
and (arr_dtype := actual.dtype) != expected_dtype # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getattr
is no better than .
, it also raises an error when the attribute is not there. Nevertheless, f251900
pyproject.toml
Outdated
"PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ | ||
"TD002", # https://docs.astral.sh/ruff/rules/missing-todo-author/ | ||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"ERA", "S", "ANN", "FIX002", "TD003", "TD004", "PLR0402", "PLC0105" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S
and most ofERA
removed- I don't think we'll comply to
FIX002
. It is fine for me to leaveTODO
s. - There are a few TODOs without link. We can fix them by adding issues.
TD004
fixed
pyproject.toml
Outdated
"PD", # Pandas is here | ||
"PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ | ||
"S101", # https://docs.astral.sh/ruff/rules/assert/ | ||
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pyproject.toml
Outdated
"PLC0415", # https://docs.astral.sh/ruff/rules/import-outside-top-level/ | ||
"S101", # https://docs.astral.sh/ruff/rules/assert/ | ||
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ | ||
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved below
pyproject.toml
Outdated
"S301", # https://docs.astral.sh/ruff/rules/suspicious-pickle-usage/ | ||
"SLF001", # https://docs.astral.sh/ruff/rules/private-member-access/ | ||
# The following rules are ignored temporarily. Either fix them or move to the permanent list above. | ||
"ANN", "ARG", "ERA", "RUF", "SIM", "TRY", "PT", "NPY", "N", "DTZ", "PLR", "TC", "PGH", "PTH", "S311", "C901", "FIX", "TD", "A001", "PYI042", "ANN201" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIX
andTD
now more detailedANN201
will be fixed in a separate PR
/pandas_nightly |
/mypy_nightly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cmp0xff
ruff
rules usually improve the code quality. By specifyingignore
rather thanselect
, we get better hints how to comply to more rules.In many cases this reduces errors in
pyright
strict, hence contributing to #1171.For example, if we comply to
ANN201
, test functions will be foreced to have-> None
, which reducespyright
strict errors. This was discussed in #1405 (comment).