Skip to content

Commit e1b5b0d

Browse files
[flake8-import-conventions] Add import numpy.typing as npt to default flake8-import-conventions.aliases (#17133)
## Summary Adds import `numpy.typing as npt` to `default in flake8-import-conventions.aliases` Resolves #17028 ## Test Plan Manually ran local ruff on the altered fixture and also ran `cargo test`
1 parent f630248 commit e1b5b0d

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

crates/ruff/tests/lint.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ requires-python = ">= 3.11"
22442244
matplotlib.pyplot = plt,
22452245
networkx = nx,
22462246
numpy = np,
2247+
numpy.typing = npt,
22472248
pandas = pd,
22482249
panel = pn,
22492250
plotly.express = px,
@@ -2554,6 +2555,7 @@ requires-python = ">= 3.11"
25542555
matplotlib.pyplot = plt,
25552556
networkx = nx,
25562557
numpy = np,
2558+
numpy.typing = npt,
25572559
pandas = pd,
25582560
panel = pn,
25592561
plotly.express = px,
@@ -2916,6 +2918,7 @@ from typing import Union;foo: Union[int, str] = 1
29162918
matplotlib.pyplot = plt,
29172919
networkx = nx,
29182920
numpy = np,
2921+
numpy.typing = npt,
29192922
pandas = pd,
29202923
panel = pn,
29212924
plotly.express = px,
@@ -3294,6 +3297,7 @@ from typing import Union;foo: Union[int, str] = 1
32943297
matplotlib.pyplot = plt,
32953298
networkx = nx,
32963299
numpy = np,
3300+
numpy.typing = npt,
32973301
pandas = pd,
32983302
panel = pn,
32993303
plotly.express = px,
@@ -3620,6 +3624,7 @@ from typing import Union;foo: Union[int, str] = 1
36203624
matplotlib.pyplot = plt,
36213625
networkx = nx,
36223626
numpy = np,
3627+
numpy.typing = npt,
36233628
pandas = pd,
36243629
panel = pn,
36253630
plotly.express = px,
@@ -3946,6 +3951,7 @@ from typing import Union;foo: Union[int, str] = 1
39463951
matplotlib.pyplot = plt,
39473952
networkx = nx,
39483953
numpy = np,
3954+
numpy.typing = npt,
39493955
pandas = pd,
39503956
panel = pn,
39513957
plotly.express = px,
@@ -4229,6 +4235,7 @@ from typing import Union;foo: Union[int, str] = 1
42294235
matplotlib.pyplot = plt,
42304236
networkx = nx,
42314237
numpy = np,
4238+
numpy.typing = npt,
42324239
pandas = pd,
42334240
panel = pn,
42344241
plotly.express = px,
@@ -4565,6 +4572,7 @@ from typing import Union;foo: Union[int, str] = 1
45654572
matplotlib.pyplot = plt,
45664573
networkx = nx,
45674574
numpy = np,
4575+
numpy.typing = npt,
45684576
pandas = pd,
45694577
panel = pn,
45704578
plotly.express = px,

crates/ruff/tests/snapshots/show_settings__display_default_settings.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ linter.flake8_import_conventions.aliases = {
250250
matplotlib.pyplot = plt,
251251
networkx = nx,
252252
numpy = np,
253+
numpy.typing = npt,
253254
pandas = pd,
254255
panel = pn,
255256
plotly.express = px,

crates/ruff_linter/resources/test/fixtures/flake8_import_conventions/custom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@
4646
import pyarrow as pa # conventional
4747

4848
from tensorflow.keras import Model # conventional
49+
50+
import numpy.typing # unconventional
51+
import numpy.typing as nt # unconventional
52+
import numpy.typing as npt # conventional

crates/ruff_linter/src/rules/flake8_import_conventions/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const CONVENTIONAL_ALIASES: &[(&str, &str)] = &[
1515
("matplotlib.pyplot", "plt"),
1616
("networkx", "nx"),
1717
("numpy", "np"),
18+
("numpy.typing", "npt"),
1819
("pandas", "pd"),
1920
("seaborn", "sns"),
2021
("tensorflow", "tf"),

crates/ruff_linter/src/rules/flake8_import_conventions/snapshots/ruff_linter__rules__flake8_import_conventions__tests__custom.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,23 @@ custom.py:31:19: ICN001 `pyarrow` should be imported as `pa`
304304
33 | import altair as alt # conventional
305305
|
306306
= help: Alias `pyarrow` to `pa`
307+
308+
custom.py:50:8: ICN001 `numpy.typing` should be imported as `npt`
309+
|
310+
48 | from tensorflow.keras import Model # conventional
311+
49 |
312+
50 | import numpy.typing # unconventional
313+
| ^^^^^^^^^^^^ ICN001
314+
51 | import numpy.typing as nt # unconventional
315+
52 | import numpy.typing as npt # conventional
316+
|
317+
= help: Alias `numpy.typing` to `npt`
318+
319+
custom.py:51:24: ICN001 `numpy.typing` should be imported as `npt`
320+
|
321+
50 | import numpy.typing # unconventional
322+
51 | import numpy.typing as nt # unconventional
323+
| ^^ ICN001
324+
52 | import numpy.typing as npt # conventional
325+
|
326+
= help: Alias `numpy.typing` to `npt`

crates/ruff_workspace/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ pub struct Flake8ImportConventionsOptions {
14961496
/// The conventional aliases for imports. These aliases can be extended by
14971497
/// the [`extend-aliases`](#lint_flake8-import-conventions_extend-aliases) option.
14981498
#[option(
1499-
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"}"#,
1499+
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"}"#,
15001500
value_type = "dict[str, str]",
15011501
scope = "aliases",
15021502
example = r#"

0 commit comments

Comments
 (0)