Skip to content

Commit 9f62e3c

Browse files
committed
Address 'easy' review comments
1 parent f945b61 commit 9f62e3c

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

crates/red_knot_python_semantic/resources/mdtest/import/stub_packages.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ reveal_type(Hexagon().area) # revealed: int | float
106106

107107
## Inconsistent stub packages
108108

109-
Stub packages where one is a namespae package and the other is a regular package. Module resolution
110-
should stop after the first non-namespace stub package. This matches pyrights behavior.
109+
Stub packages where one is a namespace package and the other is a regular package. Module resolution
110+
should stop after the first non-namespace stub package. This matches Pyright's behavior.
111111

112112
```toml
113113
[environment]
@@ -166,7 +166,7 @@ reveal_type(Hexagon().area) # revealed: Unknown
166166

167167
The runtime package is a regular package but the stubs are namespace packages. Pyright skips the
168168
stub package if the "regular" package isn't a namespace package. I'm not aware that the behavior
169-
here is specificed, and using the stubs without probing the runtime package first requires slightly
169+
here is specified, and using the stubs without probing the runtime package first requires slightly
170170
fewer lookups.
171171

172172
```toml

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,22 @@ pub(crate) fn resolve_module_query<'db>(
3939
let name = module_name.name(db);
4040
let _span = tracing::trace_span!("resolve_module", %name).entered();
4141

42-
let Some((search_path, module)) = resolve_name(db, name) else {
42+
let Some((search_path, resolved_module)) = resolve_name(db, name) else {
4343
tracing::debug!("Module `{name}` not found in search paths");
4444
return None;
4545
};
4646

4747
tracing::trace!(
4848
"Resolved module `{name}` to `{path}`",
49-
path = module.file.path(db)
49+
path = resolved_module.file.path(db)
5050
);
5151

52-
let module = Module::new(name.clone(), module.kind, search_path, module.file);
52+
let module = Module::new(
53+
name.clone(),
54+
resolved_module.kind,
55+
search_path,
56+
resolved_module.file,
57+
);
5358

5459
Some(module)
5560
}
@@ -609,7 +614,9 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
609614
return Some((search_path.clone(), ResolvedModule { kind, file }))
610615
}
611616
Err(PackageKind::Root) => {
612-
// stubs package doesn't exist, continue with the regular package
617+
tracing::trace!(
618+
"Search path '{search_path}' contains no stub package named `{stub_name}`."
619+
)
613620
}
614621
Err(PackageKind::Regular) => {
615622
tracing::trace!(
@@ -624,7 +631,7 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
624631
"Stub-package in `{search_path} doesn't contain module: `{name}` but it is a namespace package, keep going."
625632
);
626633
// stub exists, but the module doesn't. But this is a namespace package,
627-
// keep searchig the next search path for a stub package with the same name.
634+
// keep searching the next search path for a stub package with the same name.
628635
continue;
629636
}
630637
}
@@ -633,7 +640,11 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
633640
match resolve_module_in_search_path(&resolver_state, &name, search_path) {
634641
Ok((file, kind)) => return Some((search_path.clone(), ResolvedModule { kind, file })),
635642
Err(kind) => match kind {
636-
PackageKind::Root => {}
643+
PackageKind::Root => {
644+
tracing::trace!(
645+
"Search path '{search_path}' contains no package named `{name}`."
646+
)
647+
}
637648
PackageKind::Regular => {
638649
// For regular packages, don't search the next search path. All files of that
639650
// package must be in the same location

0 commit comments

Comments
 (0)