Skip to content

Respect extension filters for explicit files with --filter-files - #2720

Merged
DanielNoord merged 1 commit into
PyCQA:mainfrom
00200200:codex/filter-explicit-file-extensions
Oct 15, 2026
Merged

DanielNoord merged 1 commit into
PyCQA:mainfrom
00200200:codex/filter-explicit-file-extensions

Conversation

@00200200

Copy link
Copy Markdown
Contributor

Fixes #1984.

With --filter-files, an explicitly supplied file bypassed the extension filter used for directory discovery. For example, isort file.txt --filter-files rewrote a .txt file under the default Python-only configuration, and isort file.py --ext txt --filter-files --check-only reported an error instead of skipping the file.

Apply the existing Config.is_supported_filetype check to regular files in the CLI's explicit-path filter. Directory arguments still reach discovery, missing paths still reach the existing broken-path handling, and explicit files without --filter-files retain their override behavior.

Validation on macOS / CPython 3.12.11, with the frozen development dependencies:

  • The eight primary regression cases produced four failures and four passes against unchanged upstream 92c56855437785000527b70c1476d1ab75dd78fd; all eight pass after the fix.
  • Full unit suite: 683 passed, 1 existing skip. Includes controls for directory arguments and explicit unsupported files without --filter-files.
  • Coverage meets the project's 99% threshold; main.py has no partially covered branches.
  • All configured lint commands pass when run directly in the prepared environment: mypy (86 source files), isort, Flake8, Ruff check/format, and Bandit. Ruff emits two existing invalid-noqa warnings in unchanged files.
  • git diff --check passes.

The initial unit run used a global isort executable in two subprocess tests; the complete suite was rerun successfully with the local environment on PATH. The tox -e lint wrapper was stopped after dependency setup and the start of mypy; the same lint commands were then completed directly. Other Python versions, platforms, compiled builds, and the separate integration/property and downstream-project suites were not run locally.

AI disclosure: OpenAI Codex assisted with investigation, implementation, regression tests, and the local checks reported above.

@DanielNoord DanielNoord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if it doens't make more sense to merge is_skipped and is_supported_filetype. Not sure why that is not just a single function.

@00200200

Copy link
Copy Markdown
Contributor Author

I checked this to see if we could consolidate them into is_skipped. There are a couple of reasons they're currently kept separate:

  1. Directory traversal pruning: is_skipped is also called on directory paths during os.walk in files.find() to prune subtrees. Directory paths don't have file extensions, so extension-based filtering doesn't apply to them.
  2. Discovery vs. skip reporting: During directory discovery, is_supported_filetype silently ignores non-Python/non-target files (like .md, .json, images), while is_skipped tracks files excluded by user configuration (--skip, --skip-glob, .gitignore) so they can be tallied in Skipped N files and shown under --verbose. If they were merged directly, every non-Python file in a scanned repository would be reported as skipped.
  3. Public API & polarity: Config.is_supported_filetype is an existing public method on Config with tests, and its polarity is opposite (True for supported filetypes, False for unsupported).

If you'd like to encapsulate the combined check so main.py stays cleaner, we could add a helper on Config (like should_filter_file(path) or an optional flag on is_skipped(path, check_filetype=False)). Let me know what you prefer!

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (92c5685) to head (9eeffd0).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2720   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files          41       41           
  Lines        3230     3231    +1     
  Branches      690      690           
=======================================
+ Hits         3210     3211    +1     
  Misses         12       12           
  Partials        8        8           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanielNoord
DanielNoord added this pull request to the merge queue Oct 15, 2026
Merged via the queue into PyCQA:main with commit f13ea91 Oct 15, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--filter-files does not consider extensions

2 participants