Skip to content

Commit

Permalink
Don't define a duplicate __init__ for dataclasses
Browse files Browse the repository at this point in the history
Closes #6399.
  • Loading branch information
refi64 committed Jul 8, 2019
1 parent 18a9fe1 commit c5288f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/plugins/dataclasses.py
Expand Up @@ -92,7 +92,7 @@ def transform(self) -> None:
'frozen': _get_decorator_bool_argument(self._ctx, 'frozen', False),
}

if decorator_arguments['init']:
if decorator_arguments['init'] and info.get('__init__') is None:
add_method(
ctx,
'__init__',
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-dataclasses.test
Expand Up @@ -16,6 +16,21 @@ Person('Jonh', 21, None) # E: Too many arguments for "Person"

[builtins fixtures/list.pyi]

[case testDataclassesCustomInit]
# flags: --python-version 3.6
from dataclasses import dataclass

@dataclass
class A:
a: int

def __init__(self, a: str) -> None:
pass

A('1')

[builtins fixtures/list.pyi]

[case testDataclassesBasicInheritance]
# flags: --python-version 3.6
from dataclasses import dataclass
Expand Down

0 comments on commit c5288f9

Please sign in to comment.