Skip to content

Commit 441438e

Browse files
committed
update tests and snapshots
1 parent cae10d5 commit 441438e

5 files changed

+38
-57
lines changed

crates/ruff_linter/src/rules/pyupgrade/mod.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod tests {
1515

1616
use crate::registry::Rule;
1717
use crate::rules::pyupgrade;
18-
use crate::settings::types::PreviewMode;
18+
1919
use crate::test::test_path;
2020
use crate::{assert_messages, settings};
2121

@@ -43,7 +43,7 @@ mod tests {
4343
#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_2.py"))]
4444
#[test_case(Rule::NonPEP585Annotation, Path::new("UP006_3.py"))]
4545
#[test_case(Rule::NonPEP604AnnotationUnion, Path::new("UP007.py"))]
46-
#[test_case(Rule::NonPEP604AnnotationUnion, Path::new("UP045.py"))]
46+
#[test_case(Rule::NonPEP604AnnotationOptional, Path::new("UP045.py"))]
4747
#[test_case(Rule::NonPEP604Isinstance, Path::new("UP038.py"))]
4848
#[test_case(Rule::OSErrorAlias, Path::new("UP024_0.py"))]
4949
#[test_case(Rule::OSErrorAlias, Path::new("UP024_1.py"))]
@@ -122,19 +122,6 @@ mod tests {
122122
Ok(())
123123
}
124124

125-
#[test]
126-
fn up007_preview() -> Result<()> {
127-
let diagnostics = test_path(
128-
Path::new("pyupgrade/UP045.py"),
129-
&settings::LinterSettings {
130-
preview: PreviewMode::Enabled,
131-
..settings::LinterSettings::for_rule(Rule::NonPEP604AnnotationUnion)
132-
},
133-
)?;
134-
assert_messages!(diagnostics);
135-
Ok(())
136-
}
137-
138125
#[test]
139126
fn async_timeout_error_alias_not_applied_py310() -> Result<()> {
140127
let diagnostics = test_path(

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP045.py.snap

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
22
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
3-
snapshot_kind: text
43
---
5-
UP045.py:5:10: UP007 [*] Use `X | Y` for type annotations
4+
UP045.py:5:10: UP045 [*] Use `X | None` for type annotations
65
|
76
5 | def f(x: Optional[str]) -> None:
8-
| ^^^^^^^^^^^^^ UP007
7+
| ^^^^^^^^^^^^^ UP045
98
6 | ...
109
|
11-
= help: Convert to `X | Y`
10+
= help: Convert to `X | None`
1211

1312
Safe fix
1413
2 2 | from typing import Optional
@@ -20,13 +19,13 @@ UP045.py:5:10: UP007 [*] Use `X | Y` for type annotations
2019
7 7 |
2120
8 8 |
2221

23-
UP045.py:9:10: UP007 [*] Use `X | Y` for type annotations
22+
UP045.py:9:10: UP045 [*] Use `X | None` for type annotations
2423
|
2524
9 | def f(x: typing.Optional[str]) -> None:
26-
| ^^^^^^^^^^^^^^^^^^^^ UP007
25+
| ^^^^^^^^^^^^^^^^^^^^ UP045
2726
10 | ...
2827
|
29-
= help: Convert to `X | Y`
28+
= help: Convert to `X | None`
3029

3130
Safe fix
3231
6 6 | ...
@@ -38,14 +37,14 @@ UP045.py:9:10: UP007 [*] Use `X | Y` for type annotations
3837
11 11 |
3938
12 12 |
4039

41-
UP045.py:14:8: UP007 [*] Use `X | Y` for type annotations
40+
UP045.py:14:8: UP045 [*] Use `X | None` for type annotations
4241
|
4342
13 | def f() -> None:
4443
14 | x: Optional[str]
45-
| ^^^^^^^^^^^^^ UP007
44+
| ^^^^^^^^^^^^^ UP045
4645
15 | x = Optional[str]
4746
|
48-
= help: Convert to `X | Y`
47+
= help: Convert to `X | None`
4948

5049
Safe fix
5150
11 11 |
@@ -57,22 +56,22 @@ UP045.py:14:8: UP007 [*] Use `X | Y` for type annotations
5756
16 16 |
5857
17 17 |
5958

60-
UP045.py:15:9: UP007 Use `X | Y` for type annotations
59+
UP045.py:15:9: UP045 Use `X | None` for type annotations
6160
|
6261
13 | def f() -> None:
6362
14 | x: Optional[str]
6463
15 | x = Optional[str]
65-
| ^^^^^^^^^^^^^ UP007
64+
| ^^^^^^^^^^^^^ UP045
6665
|
67-
= help: Convert to `X | Y`
66+
= help: Convert to `X | None`
6867

69-
UP045.py:18:15: UP007 [*] Use `X | Y` for type annotations
68+
UP045.py:18:15: UP045 [*] Use `X | None` for type annotations
7069
|
7170
18 | def f(x: list[Optional[int]]) -> None:
72-
| ^^^^^^^^^^^^^ UP007
71+
| ^^^^^^^^^^^^^ UP045
7372
19 | ...
7473
|
75-
= help: Convert to `X | Y`
74+
= help: Convert to `X | None`
7675

7776
Safe fix
7877
15 15 | x = Optional[str]
@@ -84,31 +83,31 @@ UP045.py:18:15: UP007 [*] Use `X | Y` for type annotations
8483
20 20 |
8584
21 21 |
8685

87-
UP045.py:22:10: UP007 Use `X | Y` for type annotations
86+
UP045.py:22:10: UP045 Use `X | None` for type annotations
8887
|
8988
22 | def f(x: Optional[int : float]) -> None:
90-
| ^^^^^^^^^^^^^^^^^^^^^ UP007
89+
| ^^^^^^^^^^^^^^^^^^^^^ UP045
9190
23 | ...
9291
|
93-
= help: Convert to `X | Y`
92+
= help: Convert to `X | None`
9493

95-
UP045.py:26:10: UP007 Use `X | Y` for type annotations
94+
UP045.py:26:10: UP045 Use `X | None` for type annotations
9695
|
9796
26 | def f(x: Optional[str, int : float]) -> None:
98-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP045
9998
27 | ...
10099
|
101-
= help: Convert to `X | Y`
100+
= help: Convert to `X | None`
102101

103-
UP045.py:30:10: UP007 Use `X | Y` for type annotations
102+
UP045.py:30:10: UP045 Use `X | None` for type annotations
104103
|
105104
30 | def f(x: Optional[int, float]) -> None:
106-
| ^^^^^^^^^^^^^^^^^^^^ UP007
105+
| ^^^^^^^^^^^^^^^^^^^^ UP045
107106
31 | ...
108107
|
109-
= help: Convert to `X | Y`
108+
= help: Convert to `X | None`
110109

111-
UP045.py:36:28: UP007 [*] Use `X | Y` for type annotations
110+
UP045.py:36:28: UP045 [*] Use `X | None` for type annotations
112111
|
113112
34 | # Regression test for: https://github.com/astral-sh/ruff/issues/7131
114113
35 | class ServiceRefOrValue:
@@ -117,9 +116,9 @@ UP045.py:36:28: UP007 [*] Use `X | Y` for type annotations
117116
37 | | list[ServiceSpecificationRef]
118117
38 | | | list[ServiceSpecification]
119118
39 | | ] = None
120-
| |_____^ UP007
119+
| |_____^ UP045
121120
|
122-
= help: Convert to `X | Y`
121+
= help: Convert to `X | None`
123122

124123
Safe fix
125124
33 33 |
@@ -134,14 +133,14 @@ UP045.py:36:28: UP007 [*] Use `X | Y` for type annotations
134133
41 38 |
135134
42 39 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
136135

137-
UP045.py:44:28: UP007 [*] Use `X | Y` for type annotations
136+
UP045.py:44:28: UP045 [*] Use `X | None` for type annotations
138137
|
139138
42 | # Regression test for: https://github.com/astral-sh/ruff/issues/7201
140139
43 | class ServiceRefOrValue:
141140
44 | service_specification: Optional[str]is not True = None
142-
| ^^^^^^^^^^^^^ UP007
141+
| ^^^^^^^^^^^^^ UP045
143142
|
144-
= help: Convert to `X | Y`
143+
= help: Convert to `X | None`
145144

146145
Safe fix
147146
41 41 |

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__future_annotations_pep_604_p37.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
33
---
4-
future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations
4+
future_annotations.py:40:4: UP045 [*] Use `X | None` for type annotations
55
|
66
40 | x: Optional[int] = None
7-
| ^^^^^^^^^^^^^ UP007
7+
| ^^^^^^^^^^^^^ UP045
88
41 |
99
42 | MyList: TypeAlias = Union[List[int], List[str]]
1010
|
11-
= help: Convert to `X | Y`
11+
= help: Convert to `X | None`
1212

1313
Unsafe fix
1414
37 37 | return y

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__future_annotations_pep_604_py310.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
source: crates/ruff_linter/src/rules/pyupgrade/mod.rs
33
---
4-
future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations
4+
future_annotations.py:40:4: UP045 [*] Use `X | None` for type annotations
55
|
66
40 | x: Optional[int] = None
7-
| ^^^^^^^^^^^^^ UP007
7+
| ^^^^^^^^^^^^^ UP045
88
41 |
99
42 | MyList: TypeAlias = Union[List[int], List[str]]
1010
|
11-
= help: Convert to `X | Y`
11+
= help: Convert to `X | None`
1212

1313
Safe fix
1414
37 37 | return y

crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__up007_preview.snap

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)