Skip to content

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

Merged
merged 18 commits into from
May 15, 2025
Merged

Conversation

DimitriPapadopoulos
Copy link
Contributor

No description provided.

Copy link
Member

@jorenham jorenham left a 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?

@DimitriPapadopoulos
Copy link
Contributor Author

Indeed, the underlying issue remains. I'm not familiar with ContextVar and cannot find a simple way to fix it. See Factory for contextvar default value.

@ngoldbaum
Copy link
Member

I’ll try to take a look at this next week.

@charris
Copy link
Member

charris commented Apr 25, 2025

Needs a rebase.

@jorenham
Copy link
Member

this needs a rebase

Copy link
Member

@jorenham jorenham left a 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.

@ngoldbaum
Copy link
Member

I think you need to do a little more to remove memusage, including in the type stubs, typing tests, and the __all__ for the numpy.testing._private.utils namespace.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Apr 29, 2025

I'm not sure why the compilation fails on Windows.

numpy/random/_pcg64.pyx compilation error
  [511/521] Compiling Cython source D:/a/1/s/numpy/random/_pcg64.pyx
  FAILED: numpy/random/_pcg64.cp312-win_amd64.pyd.p/numpy/random/_pcg64.pyx.c
  "cython" "-M" "--fast-fail" "-3" D:/a/1/s/numpy/random/_pcg64.pyx -o numpy/random/_pcg64.cp312-win_amd64.pyd.p/numpy/random/_pcg64.pyx.c
  [512/521] Compiling Cython source numpy/random/_generator.pyx
  [513/521] Compiling Cython source numpy/random/mtrand.pyx
  ninja: build stopped: subcommand failed.
  Activating VS 16.11.46
  INFO: automatically activated MSVC compiler environment
  INFO: autodetecting backend as ninja
  INFO: calculating backend command to run: C:\hostedtoolcache\windows\Python\3.12.10\x64\Scripts\ninja.EXE
  error: subprocess-exited-with-error
  
  Preparing metadata (pyproject.toml) did not run successfully.
  exit code: 1
  
  See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: 'C:\hostedtoolcache\windows\Python\3.12.10\x64\python.exe' 'C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\VSSADM~1\AppData\Local\Temp\tmpxa2humy0'
  cwd: D:\a\1\s
  Preparing metadata (pyproject.toml): finished with status 'error'
error: metadata-generation-failed

Encountered error while generating package metadata.

@ngoldbaum
Copy link
Member

That's odd, let's see if it's reproducible. I re-triggered the failed build.

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the B branch 2 times, most recently from 60c2e37 to 6c2bb69 Compare May 13, 2025 16:41
@DimitriPapadopoulos
Copy link
Contributor Author

Rebased to fix conflicts.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented May 13, 2025

I think B006 should be applied, especially in the public API. However, this is better left to a later PR, as some of the mutable arguments are used on purpose. I would nevertheless recommend fixing all occurrences, including those on purpose, even if the code is more verbose. For example:

def action(cache=[]):
    ...

should be changed to:

_cache = []

def action(cache=None):
    if cache is None:
        cache = _cache
    ...

I find the intent is easier to understand.

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.
DimitriPapadopoulos and others added 14 commits May 15, 2025 09:29
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>
The memusage function is only exercised in typing tests.
@jorenham jorenham merged commit 71faac1 into numpy:main May 15, 2025
74 checks passed
@jorenham
Copy link
Member

Thanks Dimitri!

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.

4 participants
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