Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT: Apply assorted ruff/Pylint Refactor rules (PLR) #28755

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

DimitriPapadopoulos
Copy link
Contributor

No description provided.

Class method defined without decorator
Cannot have defined parameters for properties
Useless `return` statement at end of function
Consider merging multiple comparisons.
Use a `set` if the elements are hashable.
Use `elif` instead of `else` then `if`, to reduce indentation
Use a set literal when testing for membership
@@ -1426,7 +1426,7 @@ def normalize_axis_tuple(axis, ndim, argname=None, allow_duplicate=False):
normalize_axis_index : normalizing a single scalar axis
"""
# Optimization to speed-up the most common cases.
if type(axis) not in (tuple, list):
if type(axis) not in {tuple, list}:
Copy link
Member

Choose a reason for hiding this comment

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

same story as above

Suggested change
if type(axis) not in {tuple, list}:
if not isinstance(axis, tuple | list):

@@ -148,7 +148,7 @@ def _setfieldnames(self, names, titles):
attribute """

if names:
if type(names) in [list, tuple]:
if type(names) in {list, tuple}:
Copy link
Member

Choose a reason for hiding this comment

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

same story as above

Suggested change
if type(names) in {list, tuple}:
if isinstance(names, list | tuple):

raise AttributeError("Cannot set '%s' attribute" % attr)
fielddict = nt.void.__getattribute__(self, 'dtype').fields
res = fielddict.get(attr, None)
if res:
return self.setfield(val, *res[:2])
elif getattr(self, attr, None):
Copy link
Member

Choose a reason for hiding this comment

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

some other ruff rule will complain about this later anyway, so might as well do

Suggested change
elif getattr(self, attr, None):
if getattr(self, attr, None):

@@ -586,7 +586,7 @@ def expand_dims(a, axis):
else:
a = asanyarray(a)

if type(axis) not in (tuple, list):
if type(axis) not in {tuple, list}:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if type(axis) not in {tuple, list}:
if not isinstance(axis, tuple | list):

@@ -3929,7 +3929,7 @@ def test_quantile_identification_equation(self, weights, method, alpha):
w = rng.integers(low=0, high=10, size=n) if weights else None
x = np.quantile(y, alpha, method=method, weights=w)

if method in ("higher",):
if method in {"higher",}:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if method in {"higher",}:
if method == "higher":

@@ -62,7 +62,7 @@ def get_complex_dtype(dtype):

def get_rtol(dtype):
# Choose a safe rtol
if dtype in (single, csingle):
if dtype in {single, csingle}:
Copy link
Member

Choose a reason for hiding this comment

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

this won't work; it relies on the special behavior of dtype.__eq__

member_name != "typing" and # 2024-12: type names don't match
"numpy._core" not in member.__name__ and # outside _core
member not in visited_modules # not visited yet
inspect.ismodule(member) and "numpy" in member.__name__ and not member_name.startswith("_") and member_name not in {"tests", "typing"} and "numpy._core" not in member.__name__ and member not in visited_modules # not visited yet
Copy link
Member

Choose a reason for hiding this comment

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

no linebreaks?

Comment on lines +530 to +531
lbnd = 0 if dt in {bool, np.bool} else np.iinfo(dt).min
ubnd = 2 if dt in {bool, np.bool} else np.iinfo(dt).max + 1
Copy link
Member

Choose a reason for hiding this comment

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

this isn't quite the same:

>>> np.True_.dtype in (np.bool,)
True
>>> np.True_.dtype in {np.bool}
False

@jorenham
Copy link
Member

oh sorry I didn't notice the draft status, so my review was a bit premature.

@jorenham
Copy link
Member

needs a rebase

@jorenham jorenham self-requested a review April 28, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants