Skip to content

MNT: Enforce ruff/isort rules (I) #28969

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 3 commits into from
May 15, 2025
Merged

MNT: Enforce ruff/isort rules (I) #28969

merged 3 commits into from
May 15, 2025

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented May 15, 2025

Changes are extensive. Should I split into multiple PRs? Use a more incremental approach (but how)?

I001 Import block is un-sorted or un-formatted
Not needed after applying isort.
_NBitSingle as _NBitSingle,
_NBitDouble as _NBitDouble,
_NBitLongDouble as _NBitLongDouble,
from ._array_like import (
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about the logic for this reformatting. Why the separation and parenthesis? It doesn't seem to apply when the names aren't prefixed with _.

Copy link
Member

Choose a reason for hiding this comment

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

Seems it is reserved for things like argh as argh.

Copy link
Member

Choose a reason for hiding this comment

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

@jorenham Could you explain again why doing import x as x is useful.

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos May 15, 2025

Choose a reason for hiding this comment

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

See unused-import (F401):

If an import statement is used to re-export a symbol as part of a module's public interface, consider using a "redundant" import alias, which instructs Ruff (and other tools) to respect the re-export, and avoid marking it as unused, as in:

from module import member as member

Alternatively, you can use __all__ to declare a symbol as part of the module's interface, as in:

# __init__.py
import some_module

__all__ = ["some_module"]

@charris
Copy link
Member

charris commented May 15, 2025

I am not opposed to just putting this in, one and done. I note that @jorenham tends to undo the import list expansions :)

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented May 15, 2025

If needed, I am happy to apply non-default options for the isort rules:
https://docs.astral.sh/ruff/settings/#lintisort

@charris
Copy link
Member

charris commented May 15, 2025

I am happy to apply non-default options

I'd start with the defaults before going down that rabbit hole, a later update will likely be smaller. I do wonder if import order can have an impact.

@charris charris merged commit da2dd37 into numpy:main May 15, 2025
76 checks passed
@charris
Copy link
Member

charris commented May 15, 2025

Thanks @DimitriPapadopoulos .

@jorenham
Copy link
Member

I am not opposed to just putting this in, one and done. I note that @jorenham tends to undo the import list expansions :)

Only in case of import a as b, because that's what ruff wants me to do 🤷🏻

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.

3 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