ruff/crates/red_knot_python_semantic/resources/mdtest
Micha Reiser a467e7c8d3
[red-knot] Case sensitive module resolver (#16521)
## Summary

This PR implements the first part of
https://github.com/astral-sh/ruff/discussions/16440. It ensures that Red
Knot's module resolver is case sensitive on all systems.

This PR combines a few approaches:

1. It uses `canonicalize` on non-case-sensitive systems to get the real
casing of a path. This works for as long as no symlinks or mapped
network drives (the windows `E:\` is mapped to `\\server\share` thingy).
This is the same as what Pyright does
2. If 1. fails, fall back to recursively list the parent directory and
test if the path's file name matches the casing exactly as listed in by
list dir. This is the same approach as CPython takes in its module
resolver. The main downside is that it requires more syscalls because,
unlike CPython, we Red Knot needs to invalidate its caches if a file
name gets renamed (CPython assumes that the folders are immutable).

It's worth noting that the file watching test that I added that renames
`lib.py` to `Lib.py` currently doesn't pass on case-insensitive systems.
Making it pass requires some more involved changes to `Files`. I plan to
work on this next. There's the argument that landing this PR on its own
isn't worth it without this issue being addressed. I think it's still a
good step in the right direction even when some of the details on how
and where the path case sensitive comparison is implemented.

## Test plan

I added multiple integration tests (including a failing one). I tested
that the `case-sensitivity` detection works as expected on Windows,
MacOS and Linux and that the fast-paths are taken accordingly.
2025-03-14 19:16:44 +00:00
..
annotations [red-knot] Callable member lookup, meta type impl (#16618) 2025-03-12 12:01:38 +05:30
assignment [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
binary [red-knot] fix: improve type inference for binary ops on tuples (#16725) 2025-03-14 12:29:57 +01:00
boolean [red-knot] Statically known branches (#15019) 2024-12-21 11:33:10 +01:00
boundness_declaredness [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
call [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
comparison [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
comprehensions [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
conditional [red-knot] Diagnostics for incorrect bool usages (#16238) 2025-02-21 19:26:05 +01:00
declaration [red-knot] Avoid undeclared path when raising conflicting declarations (#14958) 2024-12-17 09:49:39 +05:30
diagnostics [red-knot] Support multiple overloads when binding parameters at call sites (#16568) 2025-03-11 15:08:17 -04:00
directives [red-knot] Add missing imports in mdtests (#15869) 2025-02-03 09:27:29 +00:00
doc [red-knot] Document 'public type of undeclared symbols' behavior (#16096) 2025-02-12 08:52:11 +01:00
exception [red-knot] MDTest: Use custom class names instead of builtins (#16269) 2025-02-20 12:25:55 +00:00
expression [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
function [red-knot] remove redundant sentence in test (#16660) 2025-03-12 04:20:31 +00:00
generics [red-knot] handle cycles in MRO/bases resolution (#16693) 2025-03-13 08:16:03 -07:00
import [red-knot] Case sensitive module resolver (#16521) 2025-03-14 19:16:44 +00:00
literal [red-knot] Migrate bool/str/repr unit tests to Markdown tests (#15534) 2025-01-16 11:21:56 -08:00
loops [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
narrow [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
regression [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
scopes [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
shadowing [red-knot] Merge Markdown code blocks inside a single section (#15950) 2025-02-05 22:26:15 +01:00
snapshots [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
stubs [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
subscript [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
suppressions [red-knot] Attribute access and the descriptor protocol (#16416) 2025-03-07 22:03:28 +01:00
type_of [red-knot] Method calls and the descriptor protocol (#16121) 2025-02-20 23:22:26 +01:00
type_properties [red-knot] Check gradual equivalence between callable types (#16634) 2025-03-13 08:16:51 +05:30
type_qualifiers [red-knot] Preliminary tests for typing.Final (#15917) 2025-03-14 12:30:13 +01:00
unary [red-knot] Diagnostics for incorrect bool usages (#16238) 2025-02-21 19:26:05 +01:00
with [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
.mdformat.toml [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
attributes.md [red-knot] Assignments to attributes (#16705) 2025-03-14 12:15:41 +01:00
descriptor_protocol.md [red-knot] Assignments to attributes (#16705) 2025-03-14 12:15:41 +01:00
final.md [red-knot] Add support for @final classes (#15070) 2024-12-19 21:02:14 +00:00
intersection_types.md [red-knot] Add missing imports in mdtests (#15869) 2025-02-03 09:27:29 +00:00
invalid_syntax.md [red-knot] Understand typing.Callable (#16493) 2025-03-08 03:58:52 +00:00
known_constants.md [red-knot] Add rule invalid-type-checking-constant (#16501) 2025-03-04 19:49:34 +00:00
mdtest_config.md [red-knot] Add missing imports in mdtests (#15869) 2025-02-03 09:27:29 +00:00
mdtest_custom_typeshed.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
metaclass.md [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
mro.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
pep695_type_aliases.md [red-knot] Move type_alias_types test to Markdown (#15607) 2025-01-20 09:55:54 +01:00
protocols.md [red-knot] Method calls and the descriptor protocol (#16121) 2025-02-20 23:22:26 +01:00
slots.md [red-knot] fix: improve type inference for binary ops on tuples (#16725) 2025-03-14 12:29:57 +01:00
statically_known_branches.md [red-knot] Litate tests: minor follow-up (#15987) 2025-02-06 07:15:26 +00:00
sys_platform.md [red-knot] Method calls and the descriptor protocol (#16121) 2025-02-20 23:22:26 +01:00
sys_version_info.md [red-knot] Merge Markdown code blocks inside a single section (#15950) 2025-02-05 22:26:15 +01:00
terminal_statements.md [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
type_api.md [red-knot] Add CallableTypeFromFunction special form (#16683) 2025-03-13 07:49:34 +05:30
union_types.md [red-knot] add special case for float/complex (#16166) 2025-02-14 12:24:10 -08:00
unpacking.md [red-knot] Support unpacking with target (#16469) 2025-03-08 02:36:35 +00:00