@@ -33,6 +33,22 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/function/return_type.md
333318 |
343419 | def j() -> str: # error: [invalid-return-type]
353520 | yield 42
36+ 21 |
37+ 22 | def invalid_return_type() -> typing.Generator[None, None, None]:
38+ 23 | yield
39+ 24 | return "" # error: [invalid-return-type]
40+ 25 | def wrong_return() -> typing.Generator[int, int, int]:
41+ 26 | yield 1
42+ 27 | return "" # error: [invalid-return-type]
43+ 28 | def bare_return_ok() -> typing.Generator[int, int, None]:
44+ 29 | yield 1
45+ 30 |
46+ 31 | def missing_return() -> typing.Generator[int, int, int]: # error: [invalid-return-type]
47+ 32 | yield 1
48+ 33 | def iterator_must_not_return() -> typing.Iterator[int]:
49+ 34 | yield 2
50+ 35 | # error: [invalid-return-type]
51+ 36 | return "foo"
3652```
3753
3854# Diagnostics
@@ -52,3 +68,72 @@ info: See https://docs.python.org/3/glossary.html#term-generator for more detail
5268info: rule `invalid-return-type` is enabled by default
5369
5470```
71+
72+ ```
73+ error[invalid-return-type]: Return type does not match returned value
74+ --> src/mdtest_snippet.py:22:30
75+ |
76+ 20 | yield 42
77+ 21 |
78+ 22 | def invalid_return_type() -> typing.Generator[None, None, None]:
79+ | ---------------------------------- Expected `None` because of return type
80+ 23 | yield
81+ 24 | return "" # error: [invalid-return-type]
82+ | ^^ expected `None`, found `Literal[""]`
83+ 25 | def wrong_return() -> typing.Generator[int, int, int]:
84+ 26 | yield 1
85+ |
86+ info: rule `invalid-return-type` is enabled by default
87+
88+ ```
89+
90+ ```
91+ error[invalid-return-type]: Return type does not match returned value
92+ --> src/mdtest_snippet.py:25:23
93+ |
94+ 23 | yield
95+ 24 | return "" # error: [invalid-return-type]
96+ 25 | def wrong_return() -> typing.Generator[int, int, int]:
97+ | ------------------------------- Expected `int` because of return type
98+ 26 | yield 1
99+ 27 | return "" # error: [invalid-return-type]
100+ | ^^ expected `int`, found `Literal[""]`
101+ 28 | def bare_return_ok() -> typing.Generator[int, int, None]:
102+ 29 | yield 1
103+ |
104+ info: rule `invalid-return-type` is enabled by default
105+
106+ ```
107+
108+ ```
109+ error[invalid-return-type]: Function always implicitly returns `None`, which is not assignable to return type `int`
110+ --> src/mdtest_snippet.py:31:25
111+ |
112+ 29 | yield 1
113+ 30 |
114+ 31 | def missing_return() -> typing.Generator[int, int, int]: # error: [invalid-return-type]
115+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116+ 32 | yield 1
117+ 33 | def iterator_must_not_return() -> typing.Iterator[int]:
118+ |
119+ info: Consider changing the return annotation to `-> None` or adding a `return` statement
120+ info: rule `invalid-return-type` is enabled by default
121+
122+ ```
123+
124+ ```
125+ error[invalid-return-type]: Return type does not match returned value
126+ --> src/mdtest_snippet.py:33:35
127+ |
128+ 31 | def missing_return() -> typing.Generator[int, int, int]: # error: [invalid-return-type]
129+ 32 | yield 1
130+ 33 | def iterator_must_not_return() -> typing.Iterator[int]:
131+ | -------------------- Expected `None` because of return type
132+ 34 | yield 2
133+ 35 | # error: [invalid-return-type]
134+ 36 | return "foo"
135+ | ^^^^^ expected `None`, found `Literal["foo"]`
136+ |
137+ info: rule `invalid-return-type` is enabled by default
138+
139+ ```
0 commit comments