Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37ee833

Browse files
committed
Add more tests
1 parent 6dee499 commit 37ee833

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

mypy/fastparse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ def do_func_def(
986986
# Determine end of the function definition itself
987987
# Fall back to the end of the function definition including its body
988988
def_end_line: int | None = n.lineno
989+
# TODO: to go to the end of the function name: n.col_offset + 4 + len(n.name)
989990
def_end_column: int | None = n.col_offset
990991

991992
returns = n.returns

mypy/messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ def span_from_context(ctx: Context) -> Iterable[int]:
265265
if isinstance(context, FuncDef):
266266
end_line = context.def_end_line
267267
# column is 1-based, see also format_messages in errors.py
268-
end_column = context.def_end_column + 1 if context.def_end_column else end_column
268+
end_column = (
269+
context.def_end_column + 1 if context.def_end_column is not None else end_column
270+
)
269271

270272
self.errors.report(
271273
context.line if context else -1,

test-data/unit/check-columns.test

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,46 @@ if int():
178178
def g(x): # E:5: Function is missing a type annotation
179179
pass
180180

181+
[case testPrettyFunctionMissingTypeAnnotation]
182+
# flags: --disallow-untyped-defs --pretty
183+
def function_with_long_name():
184+
pass
185+
[out]
186+
main:2:1: error: Function is missing a return type annotation
187+
def function_with_long_name():
188+
^
189+
main:2:1: note: Use "-> None" if function does not return a value
190+
181191
[case testColumnEndFunctionMissingTypeAnnotation]
182192
# flags: --disallow-untyped-defs --show-error-end
183193
from typing import Any, Optional
184194
if int():
185-
def f(x: int, foo: Optional[str]):
195+
def f():
196+
pass
197+
198+
def f_no_return(x: int, foo: Optional[str]):
199+
pass
200+
201+
def f_default(x: int, foo: Optional[str] = None):
202+
pass
203+
204+
def f_default_untyped(x, foo = None):
186205
pass
187206

188-
def g(x: int, foo: Optional[str] = None):
207+
def f_args(x, *args):
189208
pass
190209

191-
def h(x, foo = None):
210+
def f_kwargs(x, *args, **kwargs):
192211
pass
212+
[builtins fixtures/tuple.pyi]
193213
[out]
194-
main:4:5:4:37: error: Function is missing a return type annotation
195-
main:7:5:7:44: error: Function is missing a return type annotation
196-
main:10:5:10:24: error: Function is missing a type annotation
214+
main:4:5:4:5: error: Function is missing a return type annotation
215+
main:4:5:4:5: note: Use "-> None" if function does not return a value
216+
main:7:5:7:47: error: Function is missing a return type annotation
217+
main:10:5:10:52: error: Function is missing a return type annotation
218+
main:13:5:13:40: error: Function is missing a type annotation
219+
main:16:5:16:24: error: Function is missing a type annotation
220+
main:19:5:19:36: error: Function is missing a type annotation
197221

198222
[case testColumnNameIsNotDefined]
199223
((x)) # E:3: Name "x" is not defined

0 commit comments

Comments
 (0)