diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-05-19 10:02:52 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-05-19 10:04:43 +0200 |
commit | b488ce54e30762d81c9a7eb5c43ed904ee91cf2c (patch) | |
tree | e43fe3b8b169973a69efc38fdab2cc6ffc315c0a | |
parent | eb3761504b86d6caf06feae2072f00f846e70435 (diff) | |
download | pylint-git-b488ce54e30762d81c9a7eb5c43ed904ee91cf2c.tar.gz |
Exclude ``__dict__`` from ``attribute-defined-outside-init``
Close #2909
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | pylint/checkers/classes.py | 3 | ||||
-rw-r--r-- | pylint/test/functional/attribute_defined_outside_init.py | 5 |
3 files changed, 14 insertions, 1 deletions
@@ -7,7 +7,12 @@ What's New in Pylint 2.4.0? Release date: TBA -* Fix pointer on spelling check when the error are more than one time in the same line. + +* Exclude ``__dict__`` from ``attribute-defined-outside-init`` + + Close #2909 + +* Fix pointer on spelling check when the error are more than one time in the same line. Close #2895 diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index d75107136..604b8ef45 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -823,6 +823,9 @@ a metaclass class method.", # check if any method attr is defined in is a defining method if any(node.frame().name in defining_methods for node in nodes): continue + # Exclude `__dict__` as it is already defined. + if attr == "__dict__": + continue # check attribute is defined in a parent's __init__ for parent in cnode.instance_attr_ancestors(attr): diff --git a/pylint/test/functional/attribute_defined_outside_init.py b/pylint/test/functional/attribute_defined_outside_init.py index 826b5d68b..ab5cf5f19 100644 --- a/pylint/test/functional/attribute_defined_outside_init.py +++ b/pylint/test/functional/attribute_defined_outside_init.py @@ -60,3 +60,8 @@ class Mixin(object): """Don't emit attribute-defined-outside-init for mixin classes.""" if self.defined_already: # pylint: disable=access-member-before-definition self.defined_already = None + + +class F: + def func(self): + self.__dict__ = {'foo': 'bar'} |