Skip to content

Commit

Permalink
Clean new pylint errors from the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
PCManticore committed Sep 24, 2019
1 parent e22858b commit d8ed3f1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 48 deletions.
4 changes: 2 additions & 2 deletions astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ def bootstrap(self):
The bootstrap usually involves building the AST for the builtins
module, which is required by the rest of astroid to work correctly.
"""
import astroid.raw_building
from astroid import raw_building # pylint: disable=import-outside-toplevel

astroid.raw_building._astroid_bootstrapping()
raw_building._astroid_bootstrapping()

def clear_cache(self):
"""Clear the underlying cache. Also bootstraps the builtins module."""
Expand Down
6 changes: 2 additions & 4 deletions astroid/tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER

"""Tests for basic functionality in astroid.brain."""
import io
import queue
import re

try:
import multiprocessing # pylint: disable=unused-import
Expand Down Expand Up @@ -856,8 +858,6 @@ def streams_are_fine():
PY3 only
"""
import io

for stream in (sys.stdout, sys.stderr, sys.stdin):
if not isinstance(stream, io.IOBase):
return False
Expand Down Expand Up @@ -1060,8 +1060,6 @@ def test_typing_namedtuple_dont_crash_on_no_fields(self):

class ReBrainTest(unittest.TestCase):
def test_regex_flags(self):
import re

names = [name for name in dir(re) if name.isupper()]
re_ast = MANAGER.ast_from_module_name("re")
for name in names:
Expand Down
30 changes: 1 addition & 29 deletions astroid/tests/unittest_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import builtins
import collections
import os
import socket
import sys
import unittest

Expand Down Expand Up @@ -319,20 +320,6 @@ def test_inspect_build2(self):
def test_inspect_build3(self):
self.builder.inspect_build(unittest)

@test_utils.require_version(maxver="3.0")
def test_inspect_build_instance(self):
"""test astroid tree build from a living object"""
import exceptions as builtin_exceptions

builtin_ast = self.builder.inspect_build(builtin_exceptions)
fclass = builtin_ast["OSError"]
# things like OSError.strerror are now (2.5) data descriptors on the
# class instead of entries in the __dict__ of an instance
container = fclass
self.assertIn("errno", container)
self.assertIn("strerror", container)
self.assertIn("filename", container)

def test_inspect_build_type_object(self):
builtin_ast = MANAGER.ast_from_module_name(BUILTINS)

Expand Down Expand Up @@ -449,8 +436,6 @@ def global_no_effect():
next(astroid["global_no_effect"].ilookup("CSTE2"))

def test_socket_build(self):
import socket

astroid = self.builder.module_build(socket)
# XXX just check the first one. Actually 3 objects are inferred (look at
# the socket module) but the last one as those attributes dynamically
Expand Down Expand Up @@ -716,19 +701,6 @@ def test_unknown_encoding(self):
resources.build_file("data/invalid_encoding.py")


class ModuleBuildTest(resources.SysPathSetup, FileBuildTest):
def setUp(self):
super(ModuleBuildTest, self).setUp()
abuilder = builder.AstroidBuilder()
try:
import data.module
except ImportError:
# Make pylint happy.
self.skipTest("Unable to load data.module")
else:
self.module = abuilder.module_build(data.module, "data.module")


def test_module_build_dunder_file():
"""Test that module_build() can work with modules that have the *__file__* attribute"""
module = builder.AstroidBuilder().module_build(collections)
Expand Down
7 changes: 2 additions & 5 deletions astroid/tests/unittest_modutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import os
import sys
import unittest
import xml
from xml import etree
from xml.etree import ElementTree
import tempfile
import shutil

Expand Down Expand Up @@ -120,8 +122,6 @@ class ModPathFromFileTest(unittest.TestCase):
""" given an absolute file path return the python module's path as a list """

def test_knownValues_modpath_from_file_1(self):
from xml.etree import ElementTree

self.assertEqual(
modutils.modpath_from_file(ElementTree.__file__),
["xml", "etree", "ElementTree"],
Expand Down Expand Up @@ -324,9 +324,6 @@ def test_get_all_files(self):
self.assertEqual(modules, [os.path.join(non_package, "file.py")])

def test_load_module_set_attribute(self):
import xml.etree.ElementTree
import xml

del xml.etree.ElementTree
del sys.modules["xml.etree.ElementTree"]
m = modutils.load_module_from_modpath(["xml", "etree", "ElementTree"])
Expand Down
3 changes: 1 addition & 2 deletions astroid/tests/unittest_raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import platform
import unittest

import _io
from astroid.builder import AstroidBuilder
from astroid.raw_building import (
attach_dummy_node,
Expand Down Expand Up @@ -74,8 +75,6 @@ def test_io_is__io(self):
# what io.BufferedReader is. The code that handles this
# is in astroid.raw_building.imported_member, which verifies
# the true name of the module.
import _io

builder = AstroidBuilder()
module = builder.inspect_build(_io)
buffered_reader = module.getattr("BufferedReader")[0]
Expand Down
12 changes: 8 additions & 4 deletions astroid/tests/unittest_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
from astroid.tests import resources
from astroid import transforms

try:
import numpy # pylint: disable=unused-import
except ImportError:
HAS_NUMPY = False
else:
HAS_NUMPY = True


class NonRegressionTests(resources.AstroidCacheSetupMixin, unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -76,14 +83,11 @@ def test_living_property(self):
builder._module = sys.modules[__name__]
builder.object_build(build_module("module_name", ""), Whatever)

@unittest.skipIf(not HAS_NUMPY, "Needs numpy")
def test_numpy_crash(self):
"""test don't crash on numpy"""
# a crash occurred somewhere in the past, and an
# InferenceError instead of a crash was better, but now we even infer!
try:
import numpy # pylint: disable=unused-import
except ImportError:
self.skipTest("test skipped: numpy is not available")
builder = AstroidBuilder()
data = """
from numpy import multiply
Expand Down
3 changes: 1 addition & 2 deletions astroid/tests/unittest_scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""tests for specific behaviour of astroid scoped nodes (i.e. module, class and
function)
"""
import datetime
import os
import sys
import textwrap
Expand Down Expand Up @@ -1786,8 +1787,6 @@ class ParentGetattr(Getattr):

# Test that objects analyzed through the live introspection
# aren't considered to have dynamic getattr implemented.
import datetime

astroid_builder = builder.AstroidBuilder()
module = astroid_builder.module_build(datetime)
self.assertFalse(module["timedelta"].has_dynamic_getattr())
Expand Down

0 comments on commit d8ed3f1

Please sign in to comment.