Repository navigation
[ty] Anchor default exclude patterns at the project root - #28463
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe 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. |
Memory usage reportMemory usage unchanged ✅ |
|
|
I'm very inclined to change the implementation to
It feels more consistent and matches the behavior you get when you add an exclude in the config. |
| for pattern in default_patterns { | ||
| PortableGlobPattern::parse(pattern, PortableGlobKind::Exclude) | ||
| .and_then(|exclude| Ok(excludes.add(&exclude.into_absolute(""))?)) | ||
| .and_then(|exclude| Ok(excludes.add(&exclude.into_absolute(project_root))?)) |
There was a problem hiding this comment.
We should escape project_root in case it contains characters that would be interpreted specially in a glob
There was a problem hiding this comment.
Nice catch. I'll address this in a separate PR as this also applies to user provided excludes
| .and_then(|exclude| Ok(excludes.add(&exclude.into_absolute(""))?)) | ||
| .and_then(|exclude| Ok(excludes.add(&exclude.into_absolute(project_root))?)) |
There was a problem hiding this comment.
can project_root change after we construct patterns? Like in LSP/watch mode. If so, we'll need to recompute these patterns
There was a problem hiding this comment.
It can, but the settings are recomputed in that case. The only case where we have an incorrectly anchored exclude is if loading the new settings fail. ty then uses the old settings until the user fixes the settings. This seems fine to me and is also true for user provided excludes
…aliases * origin/main: (30 commits) [ty] Respect instance dictionary storage for slotted classes (#27749) Add a GitHub repository threat model for Ruff (#28395) [ty] Preserve wrapped signatures in nominal descriptor checks (#28466) [ty] Avoid rebinding extracted method calls (#28469) Recognize quoted types in `typing.TypeForm` (#28507) Support conditional assignment to `__lazy_modules__` (#28491) Add support for `__lazy_modules__` (#28459) [`pyupgrade`] Stop recommending deprecated `ByteString` aliases (`UP035`) (#28498) [ty] Anchor default exclude patterns at the project root (#28463) [ty] Add playground command to toggle inlay hints (#28517) [ty] Ignore divergent markers when detecting descriptors (#28514) [ty] Reuse rendered union elements when displaying types (#28494) [ty] Fix assignability of bounded typevars to intersection types (#28479) [ty] Retain package listings between resolution steps (#28278) Add accessors for comparison expressions (#28485) [ty] Refactor module resolution to use a `ModuleDirectory` abstraction. (#28418) [ty] Reduce retained AST memory by shrinking expressions (#28335) Bump version to 0.16.7 (#28496) Install rustfmt before linting releases (#28495) ensure prepare release changes pass prek (#28488) ... # Conflicts: # crates/ty_python_semantic/src/types/bool.rs
Summary
Follow up to #28451 to address @zsol's finding that
--force-excludeexcluded all project files when a project was within a excluded-by-default directory. E.g., checkingty check --force-exclude dist/project --project dist/projectexcludedprojectbecause it matched the**/excludepattern.The approach taken in this PR is to anchor all default exclude patterns with the project root. That is,
**/excludegets rewritten to<project>/**/exclude. This is the same as we do for all patterns in aty.toml.This behavior is the most consistent in my view and ensures the default
excludevalues behave exactly the same as when a user adds them manually (or similar patterns) in their configuration.The main downside of it is that ty stops ignoring folders matching the default
excludepatterns when checking a folder outside a project. Let's say you haveand you run
ty check . ../in
project. ty will now also check.venv/some.pybecause the**/.venvpattern doesn't match the path insibling.I previously considered taking the same approach as Ruff. That is, for
dist/project, checkdist/project(matches no exclude pattern) but don't checkdist/as we do today (because it's outside the project root and which would match**/dist). The advantage of this approach is that it would keep excludingsibling/.venv. However, I do think the consistency with a user written configuration is more important and makes default excludes less surprising/magical.Test Plan
Added CLI tests