[Python-modules-commits] [python-flake8] 01/05: Import python-flake8_3.2.1.orig.tar.gz

Ondřej Nový onovy at moszumanska.debian.org
Fri Nov 25 19:10:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

onovy pushed a commit to tag debian/3.2.1-1
in repository python-flake8.

commit 2025f93ae018835459c660a7c435557694642afc
Author: Ondřej Nový <onovy at debian.org>
Date:   Fri Nov 25 20:01:23 2016 +0100

    Import python-flake8_3.2.1.orig.tar.gz
---
 CONTRIBUTING.rst                      |  2 +-
 PKG-INFO                              |  2 +-
 docs/source/internal/contributing.rst |  2 +-
 docs/source/release-notes/3.1.0.rst   |  4 +--
 docs/source/release-notes/3.2.0.rst   |  2 +-
 docs/source/release-notes/3.2.1.rst   | 27 ++++++++++++++++
 docs/source/release-notes/index.rst   |  1 +
 src/flake8.egg-info/PKG-INFO          |  2 +-
 src/flake8.egg-info/SOURCES.txt       |  1 +
 src/flake8/__init__.py                |  2 +-
 src/flake8/checker.py                 | 40 +++++++++++++----------
 src/flake8/defaults.py                | 25 +++++++++++++--
 src/flake8/main/options.py            |  6 ++--
 src/flake8/style_guide.py             | 60 +++++++++++++++++++++++------------
 tests/unit/test_style_guide.py        | 47 +++++++++++++++++++++++++++
 15 files changed, 171 insertions(+), 52 deletions(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 27607bc..590d8e3 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -171,7 +171,7 @@ When reviewing other people's merge requests and issues, please be
 **especially** mindful of how the words you choose can be read by someone
 else. We strive for professional code reviews that do not insult the
 contributor's intelligence or impugn their character. The code review
-should be focused on the code, it's effectiveness, and whether it is
+should be focused on the code, its effectiveness, and whether it is
 appropriate for |Flake8|.
 
 If you have the ability to edit an issue or merge request's labels, please do
diff --git a/PKG-INFO b/PKG-INFO
index f2689e9..ef15976 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: flake8
-Version: 3.2.0
+Version: 3.2.1
 Summary: the modular source code checker: pep8, pyflakes and co
 Home-page: https://gitlab.com/pycqa/flake8
 Author: Ian Cordasco
diff --git a/docs/source/internal/contributing.rst b/docs/source/internal/contributing.rst
index 27607bc..590d8e3 100644
--- a/docs/source/internal/contributing.rst
+++ b/docs/source/internal/contributing.rst
@@ -171,7 +171,7 @@ When reviewing other people's merge requests and issues, please be
 **especially** mindful of how the words you choose can be read by someone
 else. We strive for professional code reviews that do not insult the
 contributor's intelligence or impugn their character. The code review
-should be focused on the code, it's effectiveness, and whether it is
+should be focused on the code, its effectiveness, and whether it is
 appropriate for |Flake8|.
 
 If you have the ability to edit an issue or merge request's labels, please do
diff --git a/docs/source/release-notes/3.1.0.rst b/docs/source/release-notes/3.1.0.rst
index 0b81792..a51b309 100644
--- a/docs/source/release-notes/3.1.0.rst
+++ b/docs/source/release-notes/3.1.0.rst
@@ -22,7 +22,7 @@ You can view the `3.1.0 milestone`_ on GitLab for more details.
   SyntaxErrors that occur at a newline, this caused the position to be
   visually off by two. (See also `GitLab#237`_)
 
-- Fix the behaviour of ``--enable-extenstions``. Previously, items specified
+- Fix the behaviour of ``--enable-extensions``. Previously, items specified
   here were still ignored due to the fact that the off-by-default extension
   codes were being left in the ``ignore`` list. (See also `GitLab#239`_)
 
@@ -35,7 +35,7 @@ You can view the `3.1.0 milestone`_ on GitLab for more details.
   have fixed this bug. (See also `GitLab#245`_)
 
 - Add new File Processor attribute, ``previous_unindented_logical_line`` to
-  accomodate pycodestyle 2.1.0. (See also `GitLab#246`_)
+  accommodate pycodestyle 2.1.0. (See also `GitLab#246`_)
 
 - When something goes wrong, exit non-zero. (See also `GitLab#248`_,
   `GitLab#209`_)
diff --git a/docs/source/release-notes/3.2.0.rst b/docs/source/release-notes/3.2.0.rst
index c360f64..123bc33 100644
--- a/docs/source/release-notes/3.2.0.rst
+++ b/docs/source/release-notes/3.2.0.rst
@@ -1,4 +1,4 @@
-3.1.1 -- 2016-11-14
+3.2.0 -- 2016-11-14
 -------------------
 
 You can view the `3.2.0 milestone`_ on GitLab for more details.
diff --git a/docs/source/release-notes/3.2.1.rst b/docs/source/release-notes/3.2.1.rst
new file mode 100644
index 0000000..16d4f28
--- /dev/null
+++ b/docs/source/release-notes/3.2.1.rst
@@ -0,0 +1,27 @@
+3.2.1 -- 2016-11-21
+-------------------
+
+You can view the `3.2.1 milestone`_ on GitLab for more details.
+
+- Fix subtle bug when deciding whether to report an on-by-default's violation
+  (See also `GitLab#257`_)
+
+- Fix another bug around SyntaxErrors not being reported at the right column
+  and row (See also `GitLab#259`_ and `GitLab#237`_ for a related, previously
+  fixed bug)
+
+- Fix regression from 2.x where we run checks against explicitly provided
+  files, even if they don't match the filename patterns. (See also
+  `GitLab#266`_)
+
+.. links
+.. _3.2.1 milestone:
+    https://gitlab.com/pycqa/flake8/milestones/15
+.. _GitLab#237:
+    https://gitlab.com/pycqa/flake8/issues/237
+.. _GitLab#257:
+    https://gitlab.com/pycqa/flake8/issues/257
+.. _GitLab#259:
+    https://gitlab.com/pycqa/flake8/issues/259
+.. _GitLab#266:
+    https://gitlab.com/pycqa/flake8/issues/266
diff --git a/docs/source/release-notes/index.rst b/docs/source/release-notes/index.rst
index 4bdbed3..aa86351 100644
--- a/docs/source/release-notes/index.rst
+++ b/docs/source/release-notes/index.rst
@@ -9,6 +9,7 @@ with the newest releases first.
 ==================
 
 .. toctree::
+    3.2.1
     3.2.0
     3.1.1
     3.1.0
diff --git a/src/flake8.egg-info/PKG-INFO b/src/flake8.egg-info/PKG-INFO
index f2689e9..ef15976 100644
--- a/src/flake8.egg-info/PKG-INFO
+++ b/src/flake8.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: flake8
-Version: 3.2.0
+Version: 3.2.1
 Summary: the modular source code checker: pep8, pyflakes and co
 Home-page: https://gitlab.com/pycqa/flake8
 Author: Ian Cordasco
diff --git a/src/flake8.egg-info/SOURCES.txt b/src/flake8.egg-info/SOURCES.txt
index 4dfa338..0810bff 100644
--- a/src/flake8.egg-info/SOURCES.txt
+++ b/src/flake8.egg-info/SOURCES.txt
@@ -74,6 +74,7 @@ docs/source/release-notes/3.0.4.rst
 docs/source/release-notes/3.1.0.rst
 docs/source/release-notes/3.1.1.rst
 docs/source/release-notes/3.2.0.rst
+docs/source/release-notes/3.2.1.rst
 docs/source/release-notes/index.rst
 docs/source/user/.keep
 docs/source/user/configuration.rst
diff --git a/src/flake8/__init__.py b/src/flake8/__init__.py
index be1b12e..e6e2c22 100644
--- a/src/flake8/__init__.py
+++ b/src/flake8/__init__.py
@@ -27,7 +27,7 @@ LOG.addHandler(NullHandler())
 # Clean up after LOG config
 del NullHandler
 
-__version__ = '3.2.0'
+__version__ = '3.2.1'
 __version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit())
 
 
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index b4e22b2..7f148f4 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -275,7 +275,14 @@ class Manager(object):
             for argument in paths
             for filename in utils.filenames_from(argument,
                                                  self.is_path_excluded)
-            if should_create_file_checker(filename)
+            # NOTE(sigmavirus24): If a user explicitly specifies something,
+            # e.g, ``flake8 bin/script`` then we should run Flake8 against
+            # that. Since should_create_file_checker looks to see if the
+            # filename patterns match the filename, we want to skip that in
+            # the event that the argument and the filename are identical.
+            # If it was specified explicitly, the user intended for it to be
+            # checked.
+            if argument == filename or should_create_file_checker(filename)
         ]
         LOG.info('Checking %d files', len(self.checkers))
 
@@ -470,23 +477,22 @@ class FileChecker(object):
             # NOTE(sigmavirus24): SyntaxErrors report 1-indexed column
             # numbers. We need to decrement the column number by 1 at
             # least.
-            offset = 1
+            column_offset = 1
+            # See also: https://gitlab.com/pycqa/flake8/issues/237
             physical_line = token[-1]
-            if len(physical_line) == column and physical_line[-1] == '\n':
-                # NOTE(sigmavirus24): By default, we increment the column
-                # value so that it's always 1-indexed. The SyntaxError that
-                # we are trying to handle here will end up being 2 past
-                # the end of the line. This happens because the
-                # SyntaxError is technically the character after the
-                # new-line. For example, if the code is ``foo(\n`` then
-                # ``\n`` will be 4, the empty string will be 5 but most
-                # tools want to report the at column 4, i.e., the opening
-                # parenthesis. Semantically, having a column number of 6 is
-                # correct but not useful for tooling (e.g., editors that
-                # constantly run Flake8 for users).
-                # See also: https://gitlab.com/pycqa/flake8/issues/237
-                offset += 1
-            column -= offset
+
+            # NOTE(sigmavirus24): SyntaxErrors also don't exactly have a
+            # "physical" line so much as what was accumulated by the point
+            # tokenizing failed.
+            # See also: https://gitlab.com/pycqa/flake8/issues/237
+            lines = physical_line.rstrip('\n').split('\n')
+            row_offset = len(lines) - 1
+            logical_line = lines[0]
+            logical_line_length = len(logical_line)
+            if column > logical_line_length:
+                column = logical_line_length
+            row -= row_offset
+            column -= column_offset
         return row, column
 
     def run_ast_checks(self):
diff --git a/src/flake8/defaults.py b/src/flake8/defaults.py
index e3ac9fb..340e8a9 100644
--- a/src/flake8/defaults.py
+++ b/src/flake8/defaults.py
@@ -1,9 +1,28 @@
 """Constants that define defaults."""
 import re
 
-EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg'
-IGNORE = 'E121,E123,E126,E226,E24,E704,W503,W504'
-SELECT = 'E,F,W,C90'
+EXCLUDE = (
+    '.svn',
+    'CVS',
+    '.bzr',
+    '.hg',
+    '.git',
+    '__pycache__',
+    '.tox',
+    '.eggs',
+    '*.egg',
+)
+IGNORE = (
+    'E121',
+    'E123',
+    'E126',
+    'E226',
+    'E24',
+    'E704',
+    'W503',
+    'W504',
+)
+SELECT = ('E', 'F', 'W', 'C90')
 MAX_LINE_LENGTH = 79
 
 TRUTHY_VALUES = set(['true', '1', 't'])
diff --git a/src/flake8/main/options.py b/src/flake8/main/options.py
index 7e9b79e..9780378 100644
--- a/src/flake8/main/options.py
+++ b/src/flake8/main/options.py
@@ -63,7 +63,7 @@ def register_default_options(option_manager):
     )
 
     add_option(
-        '--exclude', metavar='patterns', default=defaults.EXCLUDE,
+        '--exclude', metavar='patterns', default=','.join(defaults.EXCLUDE),
         comma_separated_list=True, parse_from_config=True,
         normalize_paths=True,
         help='Comma-separated list of files or directories to exclude.'
@@ -102,7 +102,7 @@ def register_default_options(option_manager):
     )
 
     add_option(
-        '--ignore', metavar='errors', default=defaults.IGNORE,
+        '--ignore', metavar='errors', default=','.join(defaults.IGNORE),
         parse_from_config=True, comma_separated_list=True,
         help='Comma-separated list of errors and warnings to ignore (or skip).'
              ' For example, ``--ignore=E4,E51,W234``. (Default: %default)',
@@ -116,7 +116,7 @@ def register_default_options(option_manager):
     )
 
     add_option(
-        '--select', metavar='errors', default=defaults.SELECT,
+        '--select', metavar='errors', default=','.join(defaults.SELECT),
         parse_from_config=True, comma_separated_list=True,
         help='Comma-separated list of errors and warnings to enable.'
              ' For example, ``--select=E4,E51,W234``. (Default: %default)',
diff --git a/src/flake8/style_guide.py b/src/flake8/style_guide.py
index 9f3b86f..a531b39 100644
--- a/src/flake8/style_guide.py
+++ b/src/flake8/style_guide.py
@@ -63,10 +63,16 @@ class StyleGuide(object):
         self.formatter = formatter
         self.stats = statistics.Statistics()
         self._selected = tuple(options.select)
-        self._extended_selected = tuple(options.extended_default_select)
+        self._extended_selected = tuple(sorted(
+            options.extended_default_select,
+            reverse=True,
+        ))
         self._enabled_extensions = tuple(options.enable_extensions)
-        self._all_selected = self._selected + self._enabled_extensions
-        self._ignored = tuple(options.ignore)
+        self._all_selected = tuple(sorted(
+            self._selected + self._enabled_extensions,
+            reverse=True,
+        ))
+        self._ignored = tuple(sorted(options.ignore, reverse=True))
         self._decision_cache = {}
         self._parsed_diff = {}
 
@@ -116,25 +122,21 @@ class StyleGuide(object):
 
     def _decision_for(self, code):
         # type: (Error) -> Decision
-        startswith = code.startswith
-        try:
-            selected = sorted([s for s in self._selected if startswith(s)])[0]
-        except IndexError:
-            selected = None
-        try:
-            ignored = sorted([i for i in self._ignored if startswith(i)])[0]
-        except IndexError:
-            ignored = None
-
-        if selected is None:
-            return Decision.Ignored
-
-        if ignored is None:
+        select = find_first_match(code, self._all_selected)
+        extra_select = find_first_match(code, self._extended_selected)
+        ignore = find_first_match(code, self._ignored)
+
+        if select and ignore:
+            return find_more_specific(select, ignore)
+        if extra_select and ignore:
+            return find_more_specific(extra_select, ignore)
+        if select or (extra_select and self._selected == defaults.SELECT):
             return Decision.Selected
-
-        if selected.startswith(ignored) and selected != ignored:
-            return Decision.Selected
-        return Decision.Ignored
+        if select is None and extra_select is None and ignore is not None:
+            return Decision.Ignored
+        if self._selected != defaults.SELECT and select is None:
+            return Decision.Ignored
+        return Decision.Selected
 
     def should_report_error(self, code):
         # type: (str) -> Decision
@@ -295,3 +297,19 @@ class StyleGuide(object):
             Dictionary mapping filenames to sets of line number ranges.
         """
         self._parsed_diff = diffinfo
+
+
+def find_more_specific(selected, ignored):
+    if selected.startswith(ignored) and selected != ignored:
+        return Decision.Selected
+    return Decision.Ignored
+
+
+def find_first_match(error_code, code_list):
+    startswith = error_code.startswith
+    for code in code_list:
+        if startswith(code):
+            break
+    else:
+        return None
+    return code
diff --git a/tests/unit/test_style_guide.py b/tests/unit/test_style_guide.py
index c11fd1d..7357b25 100644
--- a/tests/unit/test_style_guide.py
+++ b/tests/unit/test_style_guide.py
@@ -4,6 +4,7 @@ import optparse
 import mock
 import pytest
 
+from flake8 import defaults
 from flake8 import style_guide
 from flake8.formatting import base
 from flake8.plugins import notifier
@@ -135,6 +136,52 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
     assert guide.should_report_error(error_code) is expected
 
 
+ at pytest.mark.parametrize(
+    'select,ignore,extend_select,enabled_extensions,error_code,expected', [
+        (defaults.SELECT, [], ['I1'], [], 'I100',
+            style_guide.Decision.Selected),
+        (defaults.SELECT, [], ['I1'], [], 'I201',
+            style_guide.Decision.Selected),
+        (defaults.SELECT, ['I2'], ['I1'], [], 'I101',
+            style_guide.Decision.Selected),
+        (defaults.SELECT, ['I2'], ['I1'], [], 'I201',
+            style_guide.Decision.Ignored),
+        (defaults.SELECT, ['I1'], ['I10'], [], 'I101',
+            style_guide.Decision.Selected),
+        (defaults.SELECT, ['I10'], ['I1'], [], 'I101',
+            style_guide.Decision.Ignored),
+        (defaults.SELECT, [], [], ['U4'], 'U401',
+            style_guide.Decision.Selected),
+        (defaults.SELECT, ['U401'], [], ['U4'], 'U401',
+            style_guide.Decision.Ignored),
+        (defaults.SELECT, ['U401'], [], ['U4'], 'U402',
+            style_guide.Decision.Selected),
+        (['E2'], ['E21'], [], [], 'E221', style_guide.Decision.Selected),
+        (['E2'], ['E21'], [], [], 'E212', style_guide.Decision.Ignored),
+        (['F', 'W'], ['C90'], ['I1'], [], 'C901',
+            style_guide.Decision.Ignored),
+    ]
+)
+def test_decision_for_logic(select, ignore, extend_select, enabled_extensions,
+                            error_code, expected):
+    """Verify the complicated logic of StyleGuide._decision_for.
+
+    I usually avoid testing private methods, but this one is very important in
+    our conflict resolution work in Flake8.
+    """
+    guide = style_guide.StyleGuide(
+        create_options(
+            select=select, ignore=ignore,
+            extended_default_select=extend_select,
+            enable_extensions=enabled_extensions,
+        ),
+        listener_trie=None,
+        formatter=None,
+    )
+
+    assert guide._decision_for(error_code) is expected
+
+
 @pytest.mark.parametrize('error_code,physical_line,expected_result', [
     ('E111', 'a = 1', False),
     ('E121', 'a = 1  # noqa: E111', False),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-flake8.git



More information about the Python-modules-commits mailing list