Skip to content

Commit

Permalink
Fix message when __init__ does not have None return type
Browse files Browse the repository at this point in the history
Fixes #604.
  • Loading branch information
JukkaL committed Mar 19, 2015
1 parent 0369a5f commit 182a70b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
if (fdef.info and fdef.name() == '__init__' and
not isinstance(typ.ret_type, Void) and
not self.dynamic_funcs[-1]):
self.fail(messages.INIT_MUST_NOT_HAVE_RETURN_TYPE,
self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE,
item.type)

if name in nodes.reverse_op_method_set:
Expand Down
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
INCOMPATIBLE_TYPES_IN_YIELD = 'Incompatible types in yield'
INCOMPATIBLE_TYPES_IN_YIELD_FROM = 'Incompatible types in "yield from"'
INCOMPATIBLE_TYPES_IN_STR_INTERPOLATION = 'Incompatible types in string interpolation'
INIT_MUST_NOT_HAVE_RETURN_TYPE = 'Cannot define return type for "__init__"'
INIT_MUST_HAVE_NONE_RETURN_TYPE = 'The return type of "__init__" must be None'
GETTER_TYPE_INCOMPATIBLE_WITH_SETTER = \
'Type of getter incompatible with setter'
TUPLE_INDEX_MUST_BE_AN_INT_LITERAL = 'Tuple index must an integer literal'
Expand Down
10 changes: 9 additions & 1 deletion mypy/test/data/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,15 @@ class A:
def __init__(self) -> 'A': pass
[out]
main: In member "__init__" of class "A":
main, line 3: Cannot define return type for "__init__"
main, line 3: The return type of "__init__" must be None

[case testConstructorWithImplicitReturnValueType]
import typing
class A:
def __init__(self, x: int): pass
[out]
main: In member "__init__" of class "A":
main, line 3: The return type of "__init__" must be None

[case testGlobalFunctionInitWithReturnType]
import typing
Expand Down

0 comments on commit 182a70b

Please sign in to comment.