@@ -49,6 +49,10 @@ def results(s):
49
49
"def f(a: Callable[..., T] | DataFrame | list[int]): pass" ,
50
50
id = "Function annotation containing Subscript type" ,
51
51
),
52
+ pytest .param (
53
+ "def f(a: DataFrame | list[int]) -> int | str: pass" ,
54
+ id = "Function return annotation containing Subscript type" ,
55
+ ),
52
56
),
53
57
)
54
58
def test_noop (source ):
@@ -96,3 +100,97 @@ def test_noop(source):
96
100
def test_violation (source , expected ):
97
101
(result ,) = results (source )
98
102
assert result == expected
103
+
104
+
105
+ @pytest .mark .parametrize (
106
+ "source" ,
107
+ (
108
+ pytest .param (
109
+ "def f(foo) -> int | str | bool: pass" ,
110
+ id = "Function with multiple return type annotations" ,
111
+ ),
112
+ pytest .param (
113
+ "def foo(bar: list[int]): pass" ,
114
+ id = "Function with no return type" ,
115
+ ),
116
+ pytest .param (
117
+ "def foo(self, bar: int) -> int: pass" ,
118
+ id = "Function with one return type annotation" ,
119
+ ),
120
+ ),
121
+ )
122
+ def test_noop2 (source ):
123
+ assert not results (source )
124
+
125
+
126
+ @pytest .mark .parametrize (
127
+ "source, expected" ,
128
+ (
129
+ pytest .param (
130
+ "def bar(foo, other: tuple[Callable[..., T]] | "
131
+ "Series | list[int]) -> Series | AnyArrayLike | "
132
+ "DataFrame: pass" ,
133
+ "1:0: PDF026 found union between Series and "
134
+ "AnyArrayLike in "
135
+ "type hint" ,
136
+ id = "found union between Series and AnyArrayLike "
137
+ "in return annotations" ,
138
+ ),
139
+ pytest .param (
140
+ "def bar(foo: int, other: tuple[Callable[..., T]] | "
141
+ "Series | list[int]) -> Series | AnyArrayLike: pass" ,
142
+ "1:0: PDF026 found union between Series and "
143
+ "AnyArrayLike in "
144
+ "type hint" ,
145
+ id = "found union between Series and AnyArrayLike "
146
+ "in return annotations" ,
147
+ ),
148
+ ),
149
+ )
150
+ def test_violation2 (source , expected ):
151
+ (result ,) = results (source )
152
+ assert result == expected
153
+
154
+
155
+ @pytest .mark .parametrize (
156
+ "source" ,
157
+ (
158
+ pytest .param (
159
+ "foo: str = 'string variable'" ,
160
+ id = "Assignment with one annotation" ,
161
+ ),
162
+ pytest .param (
163
+ "self.bar: DataFrame | Timezone = [1, 2, 3]" ,
164
+ id = "Assignment with multiple annotations" ,
165
+ ),
166
+ pytest .param ("cls.foo = 3" , id = "Assignment with no annotation" ),
167
+ ),
168
+ )
169
+ def test_noop3 (source ):
170
+ assert not results (source )
171
+
172
+
173
+ @pytest .mark .parametrize (
174
+ "source, expected" ,
175
+ (
176
+ pytest .param (
177
+ "self.foo: AnyArrayLike | Timezone | Series = 2" ,
178
+ "1:0: PDF026 found union between Series and "
179
+ "AnyArrayLike in "
180
+ "type hint" ,
181
+ id = "found union between Series and AnyArrayLike "
182
+ "in variable assignment" ,
183
+ ),
184
+ pytest .param (
185
+ "cls.foo: AnyArrayLike | Series = 2" ,
186
+ "1:0: PDF026 found union between Series and "
187
+ "AnyArrayLike in "
188
+ "type hint" ,
189
+ id = "found union between Series and AnyArrayLike "
190
+ "in variable assignment" ,
191
+ ),
192
+ ),
193
+ )
194
+ def test_violation3 (source , expected ):
195
+ (result ,) = results (source )
196
+ assert result == expected
0 commit comments