diff --git a/crates/ruff/tests/lint.rs b/crates/ruff/tests/lint.rs index b95b99d934..41b44d5292 100644 --- a/crates/ruff/tests/lint.rs +++ b/crates/ruff/tests/lint.rs @@ -2244,6 +2244,7 @@ requires-python = ">= 3.11" matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -2554,6 +2555,7 @@ requires-python = ">= 3.11" matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -2916,6 +2918,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -3294,6 +3297,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -3620,6 +3624,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -3946,6 +3951,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -4229,6 +4235,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, @@ -4565,6 +4572,7 @@ from typing import Union;foo: Union[int, str] = 1 matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, diff --git a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap index 7fe041a00d..c404d07c8c 100644 --- a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap +++ b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap @@ -250,6 +250,7 @@ linter.flake8_import_conventions.aliases = { matplotlib.pyplot = plt, networkx = nx, numpy = np, + numpy.typing = npt, pandas = pd, panel = pn, plotly.express = px, diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_import_conventions/custom.py b/crates/ruff_linter/resources/test/fixtures/flake8_import_conventions/custom.py index 09af781b2c..32c6240413 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_import_conventions/custom.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_import_conventions/custom.py @@ -46,3 +46,7 @@ import polars as pl # conventional import pyarrow as pa # conventional from tensorflow.keras import Model # conventional + +import numpy.typing # unconventional +import numpy.typing as nt # unconventional +import numpy.typing as npt # conventional \ No newline at end of file diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs index 1692107a13..f00406de4a 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs @@ -15,6 +15,7 @@ const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[ ("matplotlib.pyplot", "plt"), ("networkx", "nx"), ("numpy", "np"), + ("numpy.typing", "npt"), ("pandas", "pd"), ("seaborn", "sns"), ("tensorflow", "tf"), diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/snapshots/ruff_linter__rules__flake8_import_conventions__tests__custom.snap b/crates/ruff_linter/src/rules/flake8_import_conventions/snapshots/ruff_linter__rules__flake8_import_conventions__tests__custom.snap index dc6fb55713..bae5ffd77e 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/snapshots/ruff_linter__rules__flake8_import_conventions__tests__custom.snap +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/snapshots/ruff_linter__rules__flake8_import_conventions__tests__custom.snap @@ -304,3 +304,23 @@ custom.py:31:19: ICN001 `pyarrow` should be imported as `pa` 33 | import altair as alt # conventional | = help: Alias `pyarrow` to `pa` + +custom.py:50:8: ICN001 `numpy.typing` should be imported as `npt` + | +48 | from tensorflow.keras import Model # conventional +49 | +50 | import numpy.typing # unconventional + | ^^^^^^^^^^^^ ICN001 +51 | import numpy.typing as nt # unconventional +52 | import numpy.typing as npt # conventional + | + = help: Alias `numpy.typing` to `npt` + +custom.py:51:24: ICN001 `numpy.typing` should be imported as `npt` + | +50 | import numpy.typing # unconventional +51 | import numpy.typing as nt # unconventional + | ^^ ICN001 +52 | import numpy.typing as npt # conventional + | + = help: Alias `numpy.typing` to `npt` diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index e3a473b94d..a549ab9093 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -1496,7 +1496,7 @@ pub struct Flake8ImportConventionsOptions { /// The conventional aliases for imports. These aliases can be extended by /// the [`extend-aliases`](#lint_flake8-import-conventions_extend-aliases) option. #[option( - default = r#"{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "tkinter": "tk", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa", "xml.etree.ElementTree": "ET"}"#, + default = r#"{"altair": "alt", "matplotlib": "mpl", "matplotlib.pyplot": "plt", "numpy": "np", "numpy.typing": "npt", "pandas": "pd", "seaborn": "sns", "tensorflow": "tf", "tkinter": "tk", "holoviews": "hv", "panel": "pn", "plotly.express": "px", "polars": "pl", "pyarrow": "pa", "xml.etree.ElementTree": "ET"}"#, value_type = "dict[str, str]", scope = "aliases", example = r#"