diff --git a/pyproject.toml b/pyproject.toml index 3cfcddda7b5f..8c6138b47128 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 @@ -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" + [tool.ruff.lint.isort] split-on-trailing-comma = false combine-as-imports = true diff --git a/stubs/JACK-Client/jack/__init__.pyi b/stubs/JACK-Client/jack/__init__.pyi index 4f8d61bd4de0..7d567460b8ca 100644 --- a/stubs/JACK-Client/jack/__init__.pyi +++ b/stubs/JACK-Client/jack/__init__.pyi @@ -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 @@ -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: ... diff --git a/stubs/networkx/networkx/classes/graph.pyi b/stubs/networkx/networkx/classes/graph.pyi index 981d61fd0b34..02c74eafc35e 100644 --- a/stubs/networkx/networkx/classes/graph.pyi +++ b/stubs/networkx/networkx/classes/graph.pyi @@ -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 @@ -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 ) diff --git a/stubs/networkx/networkx/convert_matrix.pyi b/stubs/networkx/networkx/convert_matrix.pyi index a94e00e7ada8..b3bbd0c48d43 100644 --- a/stubs/networkx/networkx/convert_matrix.pyi +++ b/stubs/networkx/networkx/convert_matrix.pyi @@ -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 @@ -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, @@ -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: ... diff --git a/stubs/networkx/networkx/drawing/layout.pyi b/stubs/networkx/networkx/drawing/layout.pyi index 8d5f3dd1d1e9..5e14928ccebe 100644 --- a/stubs/networkx/networkx/drawing/layout.pyi +++ b/stubs/networkx/networkx/drawing/layout.pyi @@ -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): ... @@ -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): ... diff --git a/stubs/networkx/networkx/utils/misc.pyi b/stubs/networkx/networkx/utils/misc.pyi index 261e030b1df2..ea09c775ef1d 100644 --- a/stubs/networkx/networkx/utils/misc.pyi +++ b/stubs/networkx/networkx/utils/misc.pyi @@ -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", @@ -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 @@ -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: diff --git a/stubs/tensorflow/tensorflow/_aliases.pyi b/stubs/tensorflow/tensorflow/_aliases.pyi index d8beae33eb11..ad55f7fd2e39 100644 --- a/stubs/tensorflow/tensorflow/_aliases.pyi +++ b/stubs/tensorflow/tensorflow/_aliases.pyi @@ -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