Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(🐞) dmypy can check files that dont exist #18111

Open
KotlinIsland opened this issue Nov 6, 2024 · 3 comments · May be fixed by #18229
Open

(🐞) dmypy can check files that dont exist #18111

KotlinIsland opened this issue Nov 6, 2024 · 3 comments · May be fixed by #18229
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Nov 6, 2024

given

-a
 |- test.py
> dmypy run a/test.py
Daemon started
Success: no issues found in 1 source file
> dmypy run test.py
Success: no issues found in 1 source file
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Nov 6, 2024
@KotlinIsland KotlinIsland changed the title (🐞) dmpy can check files that dont exist (🐞) dmypy can check files that dont exist Nov 6, 2024
@kcornw
Copy link

kcornw commented Dec 2, 2024

Hi! I'm new to the project and currently exploring the issue you reported. As I familiarize myself with the codebase, I noticed something in the update_sources method (mypy/dmypy_server.py):

def update_sources(self, sources: list[BuildSource]) -> None:
    paths = [source.path for source in sources if source.path is not None]
    if self.following_imports():
        # Filter out directories (used for namespace packages).
        paths = [path for path in paths if self.fscache.isfile(path)]   # This line
    self.fswatcher.add_watched_paths(paths)

which filters out directories and paths that are not valid files, but it doesn't raise an error or report any issues when a path is invalid. This might be why dmypy reports success (cached previously) even when the new file doesn't exist, as it silently ignores non-existent paths, thus changed_paths in later process is empty in this case.

Since I'm still getting up to speed with the project, I'm unsure if this behavior is intentional or if it would be appropriate to modify it to raise an InvalidSourceList when invalid paths are encountered.

If this revision is deemed appropriate, I would be interested in fixing it. I’m eager to contribute and learn more about the project!

@KotlinIsland
Copy link
Contributor Author

i'm not familiar with this portion of the codebase, but one aspect that seems interesting here is what causes a match with the cache if the paths are different? is it going off module name resolution or something?

i'd say go for it, make that change and make a PR, then we can review it and see how it behaves

kcornw added a commit to kcornw/mypy that referenced this issue Dec 2, 2024
Raise `InvalidSourceList` error if new source file is not found

Fixes python#18111
@kcornw kcornw linked a pull request Dec 2, 2024 that will close this issue
@kcornw
Copy link

kcornw commented Dec 2, 2024

Hi there!

Thank you for your encouragement and insights. From what I understand, it’s not so much about matching non-existent file paths to existing ones, but rather that dmypy might be relying on previously cached results. When a file path is invalid or doesn’t exist, the daemon seems to skip it silently, which means it doesn’t update the cache or raise an error, leading to the appearance of previous success (in your example, it continues to show the result of a/test.py). I worked on a potential fix and submitted a PR for review. I’m excited to contribute and appreciate your support.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants