diff options
author | Philipp Hörist <philipp@hoerist.com> | 2019-09-25 20:37:40 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-12-04 09:33:57 +0100 |
commit | 4952320cda79c79f6868e4fb59f09e188cd9cafc (patch) | |
tree | b0a68e71f4c21388d89e3953ee9991698a8cb12f | |
parent | 3fd48b32fd3db219c9abe9a668f9e41ee673c206 (diff) | |
download | astroid-git-4952320cda79c79f6868e4fb59f09e188cd9cafc.tar.gz |
brain_gi: Don't ignore special methods
Ignoring all special methods while inspecting gi classes leads to pylint
not detecting that objects are e.g. iterable or subscriptable
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | astroid/brain/brain_gi.py | 32 |
2 files changed, 35 insertions, 1 deletions
@@ -6,6 +6,10 @@ What's New in astroid 2.4.0? ============================ Release Date: TBA +* Don't ignore special methods when inspecting gi classes + + Close #728 + * Added transform for ``scipy.gaussian`` * Added a brain for ``responses`` diff --git a/astroid/brain/brain_gi.py b/astroid/brain/brain_gi.py index 09706107..d8e47d22 100644 --- a/astroid/brain/brain_gi.py +++ b/astroid/brain/brain_gi.py @@ -29,6 +29,36 @@ _inspected_modules = {} _identifier_re = r"^[A-Za-z_]\w*$" +_special_methods = frozenset( + { + "__lt__", + "__le__", + "__eq__", + "__ne__", + "__ge__", + "__gt__", + "__iter__", + "__getitem__", + "__setitem__", + "__delitem__", + "__len__", + "__bool__", + "__nonzero__", + "__next__", + "__str__", + "__len__", + "__contains__", + "__enter__", + "__exit__", + "__repr__", + "__getattr__", + "__setattr__", + "__delattr__", + "__del__", + "__hash__", + } +) + def _gi_build_stub(parent): """ @@ -40,7 +70,7 @@ def _gi_build_stub(parent): constants = {} methods = {} for name in dir(parent): - if name.startswith("__"): + if name.startswith("__") and name not in _special_methods: continue # Check if this is a valid name in python |