Skip to content

[ty] Fix --force-exclude for directories with an excluded ancestor - #28451

Merged
MichaReiser merged 1 commit into
mainfrom
micha/ty-force-exclude-directory-ancestors
Sep 9, 2026
Merged

MichaReiser merged 1 commit into
mainfrom
micha/ty-force-exclude-directory-ancestors

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Summary

When --force-exclude is used with a directory inside an excluded ancestor, ty still checks the directory's files. Check its ancestors before walking it, consistent with how explicitly passed files are handled.

Related to astral-sh/uv#21551

Test Plan

Added CLI test

@astral-sh-bot astral-sh-bot Bot added the ty The ty type checker label Sep 9, 2026
@astral-sh-bot

astral-sh-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 97.84%. The percentage of expected errors that received a diagnostic held steady at 96.45%. The number of fully passing files held steady at 128/145.

@astral-sh-bot

astral-sh-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser MichaReiser added bug An issue describing something that isn't working, or a PR that fixes a bug cli Related to the command-line interface of Ruff or ty labels Sep 9, 2026
@MichaReiser
MichaReiser requested a review from zsol September 9, 2026 12:04
@MichaReiser
MichaReiser marked this pull request as ready for review September 9, 2026 12:04
@MichaReiser
MichaReiser requested review from a team as code owners September 9, 2026 12:04
@MichaReiser MichaReiser changed the title [ty] Respect excluded ancestors for explicit directory paths [ty] Fix --force-exclude for directories with an excluded ancestor Sep 9, 2026
Comment on lines +888 to +895
// The exclusion also applies when the passed directory is inside an excluded directory.
let output = case
.command()
.arg("--force-exclude")
.arg("out/amd64/install")
.output()?;
assert!(output.status.success(), "{output:?}");

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.

gasp this is not an mdtest?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lol.

Unfortunately not, but I've been tempted many times to make ty_project behavior mdtestable. The reason I haven't already done so is that ty_test would have to depend on ty_project, which makes incremental compilation time a little slower for typing only changes. However, it would unlock:

  • Testing scripts
  • Testing fixes
  • Testing any project behavior....

@MichaReiser
MichaReiser merged commit ad39986 into main Sep 9, 2026
71 checks passed
@MichaReiser
MichaReiser deleted the micha/ty-force-exclude-directory-ancestors branch September 9, 2026 13:06
@zsol

zsol commented Sep 9, 2026

Copy link
Copy Markdown
Member

Codex just found this:

the new depth() == 0 Adhoc check can walk above the project root, so placing a project under an external dist/ directory causes --force-exclude to skip the entire project. The pinned base reports the test error and exits 1; the PR head skips all files and exits 0 for both ty check --force-exclude and ty check --force-exclude src

@MichaReiser

Copy link
Copy Markdown
Member Author

I'll take a look. This is a little annoying 😆

zsol added a commit to astral-sh/uv that referenced this pull request Sep 10, 2026
`uv check` passes workspace members to ty as explicit paths, which
override configured exclusions. Pass `--force-exclude` when
automatically selecting members of a virtual workspace.

The rule is to honor user intent over implicit behavior:

1. Plain `uv check` from within an excluded workspace member: *still
check that member*. The current directory selects the enclosing project,
even when run from a subdirectory.
2. Plain `uv check` at a virtual workspace root: *check only
non-excluded members*. This includes respecting exclusions of ancestor
directories, e.g. excluding `vendor` also excludes `vendor/some-member`.
3. Plain `uv check` at a workspace root that defines a project: *check
the root project*, even if excluded.
4. `uv check --all-packages`: *check all members, including excluded
ones*.
5. `uv check --package $excluded_member`: *check the selected member,
even if excluded*.
6. `uv check --script script.py`: *check the selected script, even if
excluded*.
7. `uv check --no-project`, or outside a project: *leave file discovery
and exclusions to ty*. uv passes no target paths.

For selected project directories, exclusions still apply to files and
subdirectories discovered inside them. uv also continues to exclude
nested workspace members that weren't selected.

The workspace tests now use ty 0.0.80, which includes the
ancestor-exclusion fix in
[astral-sh/ruff#28451](astral-sh/ruff#28451).

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

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug cli Related to the command-line interface of Ruff or ty ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants