diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-18 17:46:02 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-18 18:00:12 +0200 |
commit | eddace81536befab793d1f1f71e77b425d5fc30a (patch) | |
tree | a0625250234b696969220b5e5c4bd59283c85b5b | |
parent | 9f041cf56372720441ff36a9a185d324f2e3703e (diff) | |
download | astroid-git-eddace81536befab793d1f1f71e77b425d5fc30a.tar.gz |
Fix all no-member in the codebase and enable the warning
-rw-r--r-- | astroid/interpreter/_import/spec.py | 1 | ||||
-rw-r--r-- | astroid/manager.py | 2 | ||||
-rw-r--r-- | astroid/node_classes.py | 38 | ||||
-rw-r--r-- | pylintrc | 2 | ||||
-rw-r--r-- | tests/unittest_scoped_nodes.py | 2 |
5 files changed, 15 insertions, 30 deletions
diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index e7593799..9d2bb593 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -291,6 +291,7 @@ def _precache_zipimporters(path=None): req_paths = tuple(path or sys.path) cached_paths = tuple(pic) new_paths = _cached_set_diff(req_paths, cached_paths) + # pylint: disable=no-member for entry_path in new_paths: try: pic[entry_path] = zipimport.zipimporter(entry_path) diff --git a/astroid/manager.py b/astroid/manager.py index 9ed53e34..90408dfc 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -219,7 +219,9 @@ class AstroidManager: except ValueError: continue try: + # pylint: disable=no-member importer = zipimport.zipimporter(eggpath + ext) + # pylint: enable=no-member zmodname = resource.replace(os.path.sep, ".") if importer.is_package(resource): zmodname = zmodname + ".__init__" diff --git a/astroid/node_classes.py b/astroid/node_classes.py index b6541433..83c49c77 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -452,19 +452,14 @@ class NodeNG: yield attr yield from () - def last_child(self): - """An optimized version of list(get_children())[-1] - - :returns: The last child, or None if no children exist. - :rtype: NodeNG or None - """ + def last_child(self): # -> Optional["NodeNG"] + """An optimized version of list(get_children())[-1]""" for field in self._astroid_fields[::-1]: attr = getattr(self, field) if not attr: # None or empty listy / tuple continue if isinstance(attr, (list, tuple)): return attr[-1] - return attr return None @@ -601,40 +596,29 @@ class NodeNG: # single node, and they rarely get looked at @decorators.cachedproperty - def fromlineno(self): - """The first line that this node appears on in the source code. - - :type: int or None - """ + def fromlineno(self) -> Optional[int]: + """The first line that this node appears on in the source code.""" if self.lineno is None: return self._fixed_source_line() - return self.lineno @decorators.cachedproperty - def tolineno(self): - """The last line that this node appears on in the source code. - - :type: int or None - """ + def tolineno(self) -> Optional[int]: + """The last line that this node appears on in the source code.""" if not self._astroid_fields: # can't have children - lastchild = None + last_child = None else: - lastchild = self.last_child() - if lastchild is None: + last_child = self.last_child() + if last_child is None: return self.fromlineno - return lastchild.tolineno + return last_child.tolineno # pylint: disable=no-member - def _fixed_source_line(self): + def _fixed_source_line(self) -> Optional[int]: """Attempt to find the line that this node appears on. We need this method since not all nodes have :attr:`lineno` set. - - :returns: The line number of this node, - or None if this could not be determined. - :rtype: int or None """ line = self.lineno _node = self @@ -108,8 +108,6 @@ disable=fixme, stop-iteration-return, # black handles these format, - # temporary until we fix the problems with InferenceContexts - no-member, # We might want to disable new checkers from master that do not exists # in latest published pylint bad-option-value, diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py index 2f06d410..287eaafd 100644 --- a/tests/unittest_scoped_nodes.py +++ b/tests/unittest_scoped_nodes.py @@ -270,7 +270,7 @@ class ModuleNodeTest(ModuleLoader, unittest.TestCase): path = resources.find("data/all.py") file_build = builder.AstroidBuilder().file_build(path, "all") with self.assertRaises(AttributeError): - # pylint: disable=pointless-statement + # pylint: disable=pointless-statement, no-member file_build.file_stream def test_stream_api(self): |