-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
MNT: Enforce ruff/flake8-bugbear rules (B) #28765
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
base: main
Are you sure you want to change the base?
Conversation
0b85500
to
6731f90
Compare
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 have the feeling that there are some threading subtleties that we might be missing here. Perhaps @ngoldbaum could also take a look at this?
Indeed, the underlying issue remains. I'm not familiar with |
I’ll try to take a look at this next week. |
Needs a rebase. |
this needs a rebase |
module_names = args.module_names + [ | ||
OTHER_MODULE_DOCS[name] | ||
for name in args.module_names | ||
if name in OTHER_MODULE_DOCS | ||
] | ||
# remove duplicates while maintaining order | ||
module_names = list(dict.fromkeys(module_names)) |
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.
Technically speaking, this is a bit different now, because this also de-duplicates args.module_names
, which didn't happen before. I can't imagine why that would be a problem, but I figured it could be worth noting 🤷🏻
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 may be missing something, but I don't think it de-duplicates args.module_names
. The code is equivalent to:
>>> args_module_names = [ 1, 1, 2, 2, 3, 3 ]
>>> module_names = args_module_names + [ x for x in args_module_names if x != 2 ]
>>>
>>> args_module_names
[1, 1, 2, 2, 3, 3]
>>> module_names
[1, 1, 2, 2, 3, 3, 1, 1, 3, 3]
>>>
>>> module_names = list(dict.fromkeys(module_names))
>>>
>>> args_module_names
[1, 1, 2, 2, 3, 3]
>>> module_names
[1, 2, 3]
>>>
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.
args.module_names
is part of module_names
, and module_names
is what's being de-duped as a whole
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.
How is args.module_names
part of module_names
? I don't get it, module_names
is a whole new list containing values copied from args.module_names
. See my example.
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.
There's nothing left for me to complain about 👌🏻. So unless @ngoldbaum has any objections, this should be good to merge.
Using `hasattr(x, "__call__")` to test if x is callable is unreliable. Use `callable(x)` for consistent results.
Do not perform function call in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable In all these cases, the argument is designed to be persistent.
Do not assert blind exception: `Exception`
Found useless expression. Either assign it to a variable or remove it.
Loop control variable overrides iterable it iterates
abstract base class has no abstract methods or properties
Star-arg unpacking after a keyword argument is strongly discouraged
`except` handlers should only be exception classes or tuples of exception classes
Do not use mutable data structures for `ContextVar` defaults
B909 Mutation to loop iterable during iteration
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
Co-authored-by: Joren Hammudoglu <jhammudoglu@gmail.com>
I think you need to do a little more to remove |
The memusage function is only exercised in typing tests.
I'm not sure why the compilation fails on Windows. numpy/random/_pcg64.pyx compilation error
|
That's odd, let's see if it's reproducible. I re-triggered the failed build. |
numpy/testing/_private/utils.py
Outdated
@@ -36,7 +36,7 @@ | |||
'assert_equal', 'assert_almost_equal', 'assert_approx_equal', | |||
'assert_array_equal', 'assert_array_less', 'assert_string_equal', | |||
'assert_array_almost_equal', 'assert_raises', 'build_err_msg', | |||
'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal', |
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.
Argh, I'm really sorry for not realizing this until now, but it turns out that np.testing._private.utils.memusage
is re-exported in the public NumPy API as np.testing.memusage
:
In [1]: import numpy as np
In [2]: np.testing.memusage
Out[2]: <function numpy.testing._private.utils.memusage()>
In [3]: np.testing.memusage?
Signature: np.testing.memusage()
Docstring: Return memory usage of running python. [Not implemented]
File: ~/.pyenv/versions/3.13.3/lib/python3.13/site-packages/numpy/testing/_private/utils.py
Type: function
So, we definitely shouldn't delete it. Sorry for pointing you in completely the wrong direction.
Now, that said, there's all kinds of cruft in the np.testing
namespace we should deprecate and clean up, but that should be in a separate PR.
Can you revert the changes that deleted memusage
? Again, sorry for pointing you in the wrong direction in my prior code review. I'm happy to do this myself if you would like me to fix my own mistake :)
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.
Sure, will do that.
This reverts commit 371b363.
No description provided.