Skip to content

Enable Ruff flake8-import-conventions (ICN) #13731

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ select = [
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"I", # isort
"ICN", # flake8-import-conventions
"N", # pep8-naming
"PGH", # pygrep-hooks
"PLC", # Pylint Convention
Expand Down Expand Up @@ -207,6 +208,12 @@ ignore = [
[tool.ruff.lint.pydocstyle]
convention = "pep257" # https://docs.astral.sh/ruff/settings/#lint_pydocstyle_convention

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
# Using "tk" causes name conflict in stdlib/tkinter/ttk.py with Style.tk
"tkinter" = "tkinter"
# Added
"numpy.typing" = "npt"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here's a request to add this alias convention to the default aliases: astral-sh/ruff#17028


[tool.ruff.lint.isort]
split-on-trailing-comma = false
combine-as-imports = true
Expand Down
4 changes: 2 additions & 2 deletions stubs/JACK-Client/jack/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
from typing import Any, Literal, NoReturn, overload
from typing_extensions import Self

import numpy
import numpy as np
from _cffi_backend import _CDataBase
from numpy.typing import NDArray

Expand Down Expand Up @@ -224,7 +224,7 @@ class OwnPort(Port):
def disconnect(self, other: str | Port | None = None) -> None: ...
def unregister(self) -> None: ...
def get_buffer(self) -> _CBufferType: ...
def get_array(self) -> NDArray[numpy.float32]: ...
def get_array(self) -> NDArray[np.float32]: ...

class OwnMidiPort(MidiPort, OwnPort):
def __init__(self, port_ptr: _CDataBase, client: Client) -> None: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/classes/graph.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from functools import cached_property
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Self, TypeAlias

import numpy
import numpy as np
from networkx.classes.coreviews import AdjacencyView, AtlasView
from networkx.classes.digraph import DiGraph
from networkx.classes.reportviews import DiDegreeView, NodeView, OutEdgeView
Expand All @@ -22,7 +22,7 @@ _Data: TypeAlias = (
| dict[_Node, dict[_Node, dict[str, Any]]]
| dict[_Node, Iterable[_Node]]
| Iterable[_EdgePlus[_Node]]
| numpy.ndarray[Any, Any]
| np.ndarray[Any, Any]
# | scipy.sparse.base.spmatrix
)

Expand Down
18 changes: 9 additions & 9 deletions stubs/networkx/networkx/convert_matrix.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from collections.abc import Callable, Collection, Hashable, Iterable
from typing import Literal, TypeVar, overload
from typing_extensions import TypeAlias

import numpy
import numpy as np
from networkx.classes.graph import Graph, _Node
from networkx.utils.backends import _dispatchable

Expand All @@ -21,8 +21,8 @@ _G = TypeVar("_G", bound=Graph[Hashable])
def to_pandas_adjacency(
G: Graph[_Node],
nodelist: _Axes[_Node] | None = None,
dtype: numpy.dtype[Incomplete] | None = None,
order: numpy._OrderCF = None,
dtype: np.dtype[Incomplete] | None = None,
order: np._OrderCF = None,
multigraph_weight: Callable[[list[float]], float] = ...,
weight: str = "weight",
nonedge: float = 0.0,
Expand Down Expand Up @@ -72,17 +72,17 @@ def from_pandas_edgelist(
def to_numpy_array(
G: Graph[_Node],
nodelist: Collection[_Node] | None = None,
dtype: numpy.dtype[Incomplete] | None = None,
order: numpy._OrderCF = None,
dtype: np.dtype[Incomplete] | None = None,
order: np._OrderCF = None,
multigraph_weight: Callable[[list[float]], float] = ...,
weight: str = "weight",
nonedge: float = 0.0,
) -> numpy.ndarray[Incomplete, numpy.dtype[Incomplete]]: ...
) -> np.ndarray[Incomplete, np.dtype[Incomplete]]: ...
@overload
def from_numpy_array(
A: numpy.ndarray[Incomplete, Incomplete], parallel_edges: bool = False, create_using: None = None
A: np.ndarray[Incomplete, Incomplete], parallel_edges: bool = False, create_using: None = None
) -> Graph[Incomplete]: ...
@overload
def from_numpy_array(A: numpy.ndarray[Incomplete, Incomplete], parallel_edges: bool = False, *, create_using: type[_G]) -> _G: ...
def from_numpy_array(A: np.ndarray[Incomplete, Incomplete], parallel_edges: bool = False, *, create_using: type[_G]) -> _G: ...
@overload
def from_numpy_array(A: numpy.ndarray[Incomplete, Incomplete], parallel_edges: bool, create_using: type[_G]) -> _G: ...
def from_numpy_array(A: np.ndarray[Incomplete, Incomplete], parallel_edges: bool, create_using: type[_G]) -> _G: ...
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/drawing/layout.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import Incomplete

import numpy
import numpy as np

def random_layout(G, center: Incomplete | None = None, dim: int = 2, seed: Incomplete | None = None): ...
def circular_layout(G, scale: float = 1, center: Incomplete | None = None, dim: int = 2): ...
Expand Down Expand Up @@ -57,7 +57,7 @@ def arf_layout(
dt: float = 0.001,
max_iter: int = 1000,
*,
seed: int | numpy.random.RandomState | None = None,
seed: int | np.random.RandomState | None = None,
): ...
def rescale_layout(pos, scale: float = 1): ...
def rescale_layout_dict(pos, scale: float = 1): ...
6 changes: 3 additions & 3 deletions stubs/networkx/networkx/utils/misc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from _typeshed import Incomplete
from types import ModuleType
from typing_extensions import TypeAlias

import numpy
import numpy as np

__all__ = [
"flatten",
Expand All @@ -23,7 +23,7 @@ __all__ = [
]

_RandomNumberGenerator: TypeAlias = (
ModuleType | random.Random | numpy.random.RandomState | numpy.random.Generator | PythonRandomInterface
ModuleType | random.Random | np.random.RandomState | np.random.Generator | PythonRandomInterface
)
_RandomState: TypeAlias = int | _RandomNumberGenerator | None

Expand All @@ -36,7 +36,7 @@ def groups(many_to_one): ...
def create_random_state(random_state: Incomplete | None = None): ...

class PythonRandomViaNumpyBits(random.Random):
def __init__(self, rng: numpy.random.Generator | None = None) -> None: ...
def __init__(self, rng: np.random.Generator | None = None) -> None: ...
def getrandbits(self, k: int) -> int: ...

class PythonRandomInterface:
Expand Down
2 changes: 1 addition & 1 deletion stubs/tensorflow/tensorflow/_aliases.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from collections.abc import Iterable, Mapping, Sequence
from typing import Any, Protocol, TypeVar
from typing_extensions import TypeAlias

import numpy # pytype needs the unaliased import to resolve DTypeLike
import numpy # noqa: ICN001 # pytype needs the unaliased import to resolve DTypeLike
import numpy as np
import numpy.typing as npt
import tensorflow as tf
Expand Down