[ty] Allow including files with no extension#22243
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| glob_set: GlobSet, | ||
| original_patterns: Box<[String]>, | ||
| original_patterns: Box<[Box<str>]>, | ||
| literal_pattern_indices: Box<[usize]>, |
There was a problem hiding this comment.
It's a bit silly that we have to track this, given that globset has this information internally but there's no API for it.
There was a problem hiding this comment.
Hah yeah, but I think globset only tracks this sort of thing for perf. And that approach could change. So probably not a candidate for a public API unfortunately.
7a40fc5 to
7833bfa
Compare
| let source_type = if literal_match == Some(true) || entry.depth() == 0 { | ||
| Some(PySourceType::Python) | ||
| } else { | ||
| entry.path().extension().and_then(PySourceType::try_from_extension).or_else(|| db.system().source_type(entry.path())) | ||
| }; |
There was a problem hiding this comment.
Actually wait doesn't this imply include = ["a.ipynb", "b.pyi"] will both be forced to be interpretted as .py?
There was a problem hiding this comment.
The code here only filters out files that are known to be non-Python files. Resolving the source type "for real" happens in source_text.
There was a problem hiding this comment.
Is entry.path().extension().and_then(PySourceType::try_from_extension) useless then?
There was a problem hiding this comment.
Oh I think I understand what you mean -- these Option<PySourceType>'s are glorified booleans here.
There was a problem hiding this comment.
No, it is necessary to filter out files with e.g. a .txt extension when including an entire directory. db.system().source_type only returns Some for files where the source type is overriden.
| .build()?; | ||
| self.original_pattern.push(input.relative().to_string()); | ||
|
|
||
| let is_literal_pattern = globset::escape(glob_pattern) == glob_pattern; |
| glob_set: GlobSet, | ||
| original_patterns: Box<[String]>, | ||
| original_patterns: Box<[Box<str>]>, | ||
| literal_pattern_indices: Box<[usize]>, |
There was a problem hiding this comment.
Hah yeah, but I think globset only tracks this sort of thing for perf. And that approach could change. So probably not a candidate for a public API unfortunately.
Summary
This PR adds support for including files that have no extension or use a non-standard extension.
Such files can be included by explicitly listing them in the
includeconfiguration. ty will assume that those files are Python filesCloses astral-sh/ty#2235
Test Plan
Added CLI test