Skip to content

Commit

Permalink
Fix - add __post_init__ into defining-attr-methods to avoid `attr…
Browse files Browse the repository at this point in the history
…ibute-defined-outside-init` in dataclasses.
  • Loading branch information
aklajnert authored and PCManticore committed Jul 5, 2019
1 parent 298a22d commit 0eeb677
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,5 @@ contributors:
* Agustin Toledo: contributor

* Nicholas Smith: contributor

* Andrzej Klajnert: contributor
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ Release date: TBA

Close #2963

* Added ``__post_init__`` to ``defining-attr-methods`` in order to avoid ``attribute-defined-outside-init`` in dataclasses.

Close #2581

What's New in Pylint 2.3.0?
===========================

Expand Down
3 changes: 2 additions & 1 deletion examples/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,
__new__,
setUp
setUp,
__post_init__

# List of member names, which should be excluded from the protected access
# warning.
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ class ClassChecker(BaseChecker):
(
"defining-attr-methods",
{
"default": ("__init__", "__new__", "setUp"),
"default": ("__init__", "__new__", "setUp", "__post_init__"),
"type": "csv",
"metavar": "<method names>",
"help": "List of method names used to declare (i.e. assign) \
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ max-public-methods=25
[CLASSES]

# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp
defining-attr-methods=__init__,__new__,setUp,__post_init__

# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/attribute_defined_outside_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ def prop(self):
@prop.setter
def prop(self, value):
self.__prop = value

class DataClass:
def __post_init__(self):
self.a = 42

0 comments on commit 0eeb677

Please sign in to comment.