Skip to content

Commit 182a70b

Browse files
committed
Fix message when __init__ does not have None return type
Fixes #604.
1 parent 0369a5f commit 182a70b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

mypy/checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
502502
if (fdef.info and fdef.name() == '__init__' and
503503
not isinstance(typ.ret_type, Void) and
504504
not self.dynamic_funcs[-1]):
505-
self.fail(messages.INIT_MUST_NOT_HAVE_RETURN_TYPE,
505+
self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE,
506506
item.type)
507507

508508
if name in nodes.reverse_op_method_set:

mypy/messages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
INCOMPATIBLE_TYPES_IN_YIELD = 'Incompatible types in yield'
4040
INCOMPATIBLE_TYPES_IN_YIELD_FROM = 'Incompatible types in "yield from"'
4141
INCOMPATIBLE_TYPES_IN_STR_INTERPOLATION = 'Incompatible types in string interpolation'
42-
INIT_MUST_NOT_HAVE_RETURN_TYPE = 'Cannot define return type for "__init__"'
42+
INIT_MUST_HAVE_NONE_RETURN_TYPE = 'The return type of "__init__" must be None'
4343
GETTER_TYPE_INCOMPATIBLE_WITH_SETTER = \
4444
'Type of getter incompatible with setter'
4545
TUPLE_INDEX_MUST_BE_AN_INT_LITERAL = 'Tuple index must an integer literal'

mypy/test/data/check-classes.test

+9-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,15 @@ class A:
367367
def __init__(self) -> 'A': pass
368368
[out]
369369
main: In member "__init__" of class "A":
370-
main, line 3: Cannot define return type for "__init__"
370+
main, line 3: The return type of "__init__" must be None
371+
372+
[case testConstructorWithImplicitReturnValueType]
373+
import typing
374+
class A:
375+
def __init__(self, x: int): pass
376+
[out]
377+
main: In member "__init__" of class "A":
378+
main, line 3: The return type of "__init__" must be None
371379

372380
[case testGlobalFunctionInitWithReturnType]
373381
import typing

0 commit comments

Comments
 (0)