Skip to content

Inconsistent exclude behaviour #1074

Open

Description

@asottile

In GitLab by @mskrajnowski on Dec 13, 2017, 05:53

Please describe how you installed Flake8

# in a virtualenv
$ pip install flake8

Please provide the exact, unmodified output of flake8 --bug-report

{
  "dependencies": [
    {
      "dependency": "setuptools",
      "version": "34.2.0"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "2.7.12",
    "system": "Linux"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.3.1"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "1.6.0"
    },
    {
      "is_local": false,
      "plugin": "unicode-string-literal",
      "version": "1.1"
    }
  ],
  "version": "3.5.0"
}

Please describe the problem or feature

Explicitly specified modules are not always checked, depending on what exclude is set:

  • if the module is within an excluded directory it will be checked
  • if the module filename is excluded it will not be checked

I would expect flake8 to either:

  • always check files that are explicitly specified
  • always ignore files that are excluded and/or in an excluded directory

If this is a bug report, please explain with examples (and example code) what you expected to happen and what actually happened.

  1. Prepare a simple project for testing

    $ mkdir -p test-flake8-exclude/test
    $ cd test-flake8-exclude
    $ echo "import os" > test/module.py
  2. Try without exclude

    $ flake8 . && echo OK
    ./test/module.py:1:1: F401 'os' imported but unused
    $ flake8 test/module.py && echo OK
    test/module.py:1:1: F401 'os' imported but unused
  3. Try excluding the directory

    $ echo "[flake8]" > .flake8
    $ echo "exclude = test" >> .flake8
    
    $ flake8 . && echo OK
    OK
    $ flake8 test/module.py && echo OK
    test/module.py:1:1: F401 'os' imported but unused
  4. Try excluding the module

    $ echo "[flake8]" > .flake8
    $ echo "exclude = module.py" >> .flake8
    
    $ flake8 . && echo OK
    OK
    $ flake8 test/module.py && echo OK
    OK

I'd expect results in 3. and 4. to be the same.

Activity

  1. vosi commented on Sep 23, 2025

    @vosi

    getting same problem with current flake

    in my ci pipeline i'm linting only on changed files, so i first get a list of files, then apply it to flake8 $FILES command, and it completely ignores what i have in config file's exclude section (alembic migrations files in my case)

    will this be fixed?

  2. vosi commented on Sep 23, 2025

    @vosi

    i see in a code, this behavior is intentional, could we discuss a rationale behind this? since the ticket is still open, i guess it's a place for debates.
    @asottile

  3. asottile commented on Sep 23, 2025

    @asottile
    MemberAuthor

    if you've explicitly listed a file on the commandline the expectation is that you explicitly want to lint it

    this particular issue is unrelated to that -- it's about an inconsistency where file exclude is still applied in some cases (but shouldn't be)

  4. vosi commented on Sep 23, 2025

    @vosi

    aha, sorry, have inaccurately read .4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions