예제 #1
0
    def _fix_flake_import_errors(self) -> None:
        """Fix python source code to correct missed or unused import statements."""
        error_messages = autoflake.check(self._join_code())

        for message in error_messages:
            if isinstance(message, (UndefinedName, UndefinedExport)):
                object_name = message.message_args[0]
                self._add_package(object_name)
            elif isinstance(message, UnusedImport):
                import_name = message.message_args[0]
                self._remove_unused_imports(import_name)
예제 #2
0
def pyflakes_count(filename):
    """Return pyflakes error count."""
    with autoflake.open_with_encoding(
            filename, encoding=autoflake.detect_encoding(filename)) as f:
        return len(list(autoflake.check(f.read())))
예제 #3
0
    def test_check_with_unicode(self):
        self.assertFalse(autoflake.check('print("∑")'))

        self.assertTrue(autoflake.check('import os  # ∑'))
예제 #4
0
 def test_check_with_bad_syntax(self):
     self.assertFalse(autoflake.check('foo('))
예제 #5
0
 def test_check(self):
     self.assertTrue(autoflake.check('import os'))
예제 #6
0
 def test_unused_import_line_numbers_with_dot(self):
     self.assertEqual([1],
                      list(
                          autoflake.unused_import_line_numbers(
                              autoflake.check('import os.path\n'))))
예제 #7
0
 def test_unused_import_line_numbers_with_from(self):
     self.assertEqual([1],
                      list(
                          autoflake.unused_import_line_numbers(
                              autoflake.check('from os import path\n'))))
예제 #8
0
    def test_check_with_unicode(self):
        self.assertFalse(autoflake.check('print("∑")'))

        self.assertTrue(autoflake.check('import os  # ∑'))
예제 #9
0
 def test_check_with_bad_syntax(self):
     self.assertFalse(autoflake.check('foo('))
예제 #10
0
 def test_check(self):
     self.assertTrue(autoflake.check('import os'))
예제 #11
0
 def test_unused_import_line_numbers_with_dot(self):
     self.assertEqual(
         [1],
         list(autoflake.unused_import_line_numbers(
             autoflake.check('import os.path\n'))))
예제 #12
0
 def test_unused_import_line_numbers_with_from(self):
     self.assertEqual(
         [1],
         list(autoflake.unused_import_line_numbers(
             autoflake.check('from os import path\n'))))
예제 #13
0
def pyflakes_count(filename):
    """Return pyflakes error count."""
    with autoflake.open_with_encoding(
            filename,
            encoding=autoflake.detect_encoding(filename)) as f:
        return len(list(autoflake.check(f.read())))
예제 #14
0
 def test_check_with_unicode(self):
     self.assertFalse(autoflake.check('print("∑")'))