Skip to content

[ty] Checking files without extension#21867

Merged
MichaReiser merged 3 commits intomainfrom
micha/check-files-without-extensions
Dec 10, 2025
Merged

[ty] Checking files without extension#21867
MichaReiser merged 3 commits intomainfrom
micha/check-files-without-extensions

Conversation

@MichaReiser
Copy link
Member

Summary

Adds support for checking files without extensions if they're passed by name on the CLI or
if the user selects Python as the language in their editor.

Fixes astral-sh/ty#1692

Note: We don't yet support excluding a file that has a .py extension
if the user selects a non-Python language in their editor but I consider this a separate change.

Test Plan

Added end to end tests

@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Dec 9, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 9, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@MichaReiser MichaReiser requested review from Gankra and removed request for dcreager and sharkdp December 9, 2025 16:19
@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 9, 2025

mypy_primer results

Changes were detected when running on open source projects
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_typing.pyi:1217:16: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 5258 diagnostics
+ Found 5259 diagnostics

No memory usage changes detected ✅

Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

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

Ah good, this is roughly what I was expecting! Not the most thorough review (migraine winning)

.extension()
.and_then(PySourceType::try_from_extension)
.is_none()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm this check seems kinda adhoc/brittle

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't disagree. All our 'Keep the world in sync with salsa' is a bit brittle. Not sure what else to do.

@MichaReiser MichaReiser enabled auto-merge (squash) December 10, 2025 16:42
@MichaReiser MichaReiser merged commit f7528bd into main Dec 10, 2025
41 checks passed
@MichaReiser MichaReiser deleted the micha/check-files-without-extensions branch December 10, 2025 16:47
BurntSushi added a commit that referenced this pull request Feb 6, 2026
Previously, we were only setting the check mode on a project if the
diagnostic mode was `workspace`. While the diagnostic mode defaults to
`OpenFilesOnly`, the _check mode_ on a ty project defaults to `AllFiles`
(i.e., workspace).

The result is that projects were always configured in `AllFiles` check
mode, making it impossible to set the check mode to `OpenFilesOnly`.
Confusingly, this is _distinct_ from the global settings diagnostic
mode, which could actually be different thant he check mode on the
individual projects!

This did cause one test failure: an end-to-end test checking that
changing the language of a file resulted in the LSP picking up that
change. e.g., Going from Python to non-Python should result in no
diagnostics. This was added in #21867, but I believe the change was
incomplete: when a `didOpen` notification is received, we were
unconditionally adding the file to the project state without checking
its extension. The test still "worked" precisely because of the
`AllFiles` vs `OpenFilesOnly` confusion. That is, the server defaulted
to `OpenFilesOnly`, but the project defaulted to `AllFiles`. This in
turn made it so the file was an "open file" and not actually picked up
from a directory scan. That in turn led to `should_check_file` returning
false, since the `AllFiles` mode explicitly ignores "open files."

Ref astral-sh/ty#2616
BurntSushi added a commit that referenced this pull request Feb 9, 2026
Previously, we were only setting the check mode on a project if the
diagnostic mode was `workspace`. While the diagnostic mode defaults to
`OpenFilesOnly`, the _check mode_ on a ty project defaults to `AllFiles`
(i.e., workspace).

The result is that projects were always configured in `AllFiles` check
mode, making it impossible to set the check mode to `OpenFilesOnly`.
Confusingly, this is _distinct_ from the global settings diagnostic
mode, which could actually be different thant he check mode on the
individual projects!

This did cause one test failure: an end-to-end test checking that
changing the language of a file resulted in the LSP picking up that
change. e.g., Going from Python to non-Python should result in no
diagnostics. This was added in #21867, but I believe the change was
incomplete: when a `didOpen` notification is received, we were
unconditionally adding the file to the project state without checking
its extension. The test still "worked" precisely because of the
`AllFiles` vs `OpenFilesOnly` confusion. That is, the server defaulted
to `OpenFilesOnly`, but the project defaulted to `AllFiles`. This in
turn made it so the file was an "open file" and not actually picked up
from a directory scan. That in turn led to `should_check_file` returning
false, since the `AllFiles` mode explicitly ignores "open files."

Ref astral-sh/ty#2616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support checking python file without extension

2 participants