Skip to content

Commit c3b40da

Browse files
Use backticks for code in red-knot messages (#13599)
## Summary ...and remove periods from messages that don't span more than a single sentence. This is more consistent with how we present user-facing messages in uv (which has a defined style guide).
1 parent ef45185 commit c3b40da

File tree

22 files changed

+156
-156
lines changed

22 files changed

+156
-156
lines changed

crates/red_knot/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn run() -> anyhow::Result<ExitStatus> {
160160
SystemPathBuf::from_path_buf(cwd)
161161
.map_err(|path| {
162162
anyhow!(
163-
"The current working directory '{}' contains non-unicode characters. Red Knot only supports unicode paths.",
163+
"The current working directory `{}` contains non-Unicode characters. Red Knot only supports Unicode paths.",
164164
path.display()
165165
)
166166
})?
@@ -174,7 +174,7 @@ fn run() -> anyhow::Result<ExitStatus> {
174174
Ok(SystemPath::absolute(cwd, &cli_base_path))
175175
} else {
176176
Err(anyhow!(
177-
"Provided current-directory path '{cwd}' is not a directory."
177+
"Provided current-directory path `{cwd}` is not a directory"
178178
))
179179
}
180180
})

crates/red_knot/tests/file_watching.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ impl TestCase {
4242

4343
fn stop_watch(&mut self) -> Vec<watch::ChangeEvent> {
4444
self.try_stop_watch(Duration::from_secs(10))
45-
.expect("Expected watch changes but observed none.")
45+
.expect("Expected watch changes but observed none")
4646
}
4747

4848
fn try_stop_watch(&mut self, timeout: Duration) -> Option<Vec<watch::ChangeEvent>> {
4949
let watcher = self
5050
.watcher
5151
.take()
52-
.expect("Cannot call `stop_watch` more than once.");
52+
.expect("Cannot call `stop_watch` more than once");
5353

5454
let mut all_events = self
5555
.changes_receiver
@@ -72,7 +72,7 @@ impl TestCase {
7272
#[cfg(unix)]
7373
fn take_watch_changes(&self) -> Vec<watch::ChangeEvent> {
7474
self.try_take_watch_changes(Duration::from_secs(10))
75-
.expect("Expected watch changes but observed none.")
75+
.expect("Expected watch changes but observed none")
7676
}
7777

7878
fn try_take_watch_changes(&self, timeout: Duration) -> Option<Vec<watch::ChangeEvent>> {
@@ -150,14 +150,14 @@ where
150150
let absolute_path = workspace_path.join(relative_path);
151151
if let Some(parent) = absolute_path.parent() {
152152
std::fs::create_dir_all(parent).with_context(|| {
153-
format!("Failed to create parent directory for file '{relative_path}'.",)
153+
format!("Failed to create parent directory for file `{relative_path}`")
154154
})?;
155155
}
156156

157157
let mut file = std::fs::File::create(absolute_path.as_std_path())
158-
.with_context(|| format!("Failed to open file '{relative_path}'"))?;
158+
.with_context(|| format!("Failed to open file `{relative_path}`"))?;
159159
file.write_all(content.as_bytes())
160-
.with_context(|| format!("Failed to write to file '{relative_path}'"))?;
160+
.with_context(|| format!("Failed to write to file `{relative_path}`"))?;
161161
file.sync_data()?;
162162
}
163163

@@ -194,7 +194,7 @@ where
194194

195195
let root_path = SystemPath::from_std_path(temp_dir.path()).ok_or_else(|| {
196196
anyhow!(
197-
"Temp directory '{}' is not a valid UTF-8 path.",
197+
"Temporary directory `{}` is not a valid UTF-8 path.",
198198
temp_dir.path().display()
199199
)
200200
})?;
@@ -209,7 +209,7 @@ where
209209
let workspace_path = root_path.join("workspace");
210210

211211
std::fs::create_dir_all(workspace_path.as_std_path())
212-
.with_context(|| format!("Failed to create workspace directory '{workspace_path}'",))?;
212+
.with_context(|| format!("Failed to create workspace directory `{workspace_path}`"))?;
213213

214214
setup_files
215215
.setup(&root_path, &workspace_path)
@@ -233,7 +233,7 @@ where
233233
}))
234234
{
235235
std::fs::create_dir_all(path.as_std_path())
236-
.with_context(|| format!("Failed to create search path '{path}'"))?;
236+
.with_context(|| format!("Failed to create search path `{path}`"))?;
237237
}
238238

239239
let configuration = Configuration {
@@ -665,7 +665,7 @@ fn directory_deleted() -> anyhow::Result<()> {
665665

666666
let bar = case.system_file(case.workspace_path("bar.py")).unwrap();
667667

668-
assert!(resolve_module(case.db().upcast(), ModuleName::new_static("sub.a").unwrap()).is_some(),);
668+
assert!(resolve_module(case.db().upcast(), ModuleName::new_static("sub.a").unwrap()).is_some());
669669

670670
let sub_path = case.workspace_path("sub");
671671

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ pub(crate) fn resolve_module_query<'db>(
3636
let _span = tracing::trace_span!("resolve_module", %name).entered();
3737

3838
let Some((search_path, module_file, kind)) = resolve_name(db, name) else {
39-
tracing::debug!("Module '{name}' not found in the search paths.");
39+
tracing::debug!("Module `{name}` not found in search paths");
4040
return None;
4141
};
4242

4343
let module = Module::new(name.clone(), kind, search_path, module_file);
4444

4545
tracing::trace!(
46-
"Resolved module '{name}' to '{path}'.",
46+
"Resolved module `{name}` to `{path}`",
4747
path = module_file.path(db)
4848
);
4949

@@ -324,7 +324,7 @@ pub(crate) fn dynamic_resolution_paths(db: &dyn Db) -> Vec<SearchPath> {
324324

325325
let site_packages_root = files
326326
.root(db.upcast(), site_packages_dir)
327-
.expect("Site-package root to have been created.");
327+
.expect("Site-package root to have been created");
328328

329329
// This query needs to be re-executed each time a `.pth` file
330330
// is added, modified or removed from the `site-packages` directory.

crates/red_knot_python_semantic/src/site_packages.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl VirtualEnvironment {
192192
} else {
193193
tracing::warn!(
194194
"Failed to resolve `sys.prefix` of the system Python installation \
195-
from the `home` value in the `pyvenv.cfg` file at '{}'. \
195+
from the `home` value in the `pyvenv.cfg` file at `{}`. \
196196
System site-packages will not be used for module resolution.",
197197
venv_path.join("pyvenv.cfg")
198198
);
@@ -426,7 +426,7 @@ impl Deref for SysPrefixPath {
426426

427427
impl fmt::Display for SysPrefixPath {
428428
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
429-
write!(f, "`sys.prefix` path '{}'", self.0)
429+
write!(f, "`sys.prefix` path `{}`", self.0)
430430
}
431431
}
432432

@@ -483,7 +483,7 @@ impl Deref for PythonHomePath {
483483

484484
impl fmt::Display for PythonHomePath {
485485
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
486-
write!(f, "`home` location '{}'", self.0)
486+
write!(f, "`home` location `{}`", self.0)
487487
}
488488
}
489489

crates/red_knot_python_semantic/src/types.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn bindings_ty<'db>(
169169

170170
let first = all_types
171171
.next()
172-
.expect("bindings_ty should never be called with zero definitions and no unbound_ty.");
172+
.expect("bindings_ty should never be called with zero definitions and no unbound_ty");
173173

174174
if let Some(second) = all_types.next() {
175175
UnionType::from_elements(db, [first, second].into_iter().chain(all_types))
@@ -204,7 +204,7 @@ fn declarations_ty<'db>(
204204
let mut all_types = undeclared_ty.into_iter().chain(decl_types);
205205

206206
let first = all_types.next().expect(
207-
"declarations_ty must not be called with zero declarations and no may-be-undeclared.",
207+
"declarations_ty must not be called with zero declarations and no may-be-undeclared",
208208
);
209209

210210
let mut conflicting: Vec<Type<'db>> = vec![];
@@ -917,7 +917,7 @@ impl<'db> CallOutcome<'db> {
917917
node,
918918
"call-non-callable",
919919
format_args!(
920-
"Object of type '{}' is not callable.",
920+
"Object of type `{}` is not callable",
921921
not_callable_ty.display(db)
922922
),
923923
);
@@ -932,7 +932,7 @@ impl<'db> CallOutcome<'db> {
932932
node,
933933
"call-non-callable",
934934
format_args!(
935-
"Object of type '{}' is not callable (due to union element '{}').",
935+
"Object of type `{}` is not callable (due to union element `{}`)",
936936
called_ty.display(db),
937937
not_callable_ty.display(db),
938938
),
@@ -948,7 +948,7 @@ impl<'db> CallOutcome<'db> {
948948
node,
949949
"call-non-callable",
950950
format_args!(
951-
"Object of type '{}' is not callable (due to union elements {}).",
951+
"Object of type `{}` is not callable (due to union elements {})",
952952
called_ty.display(db),
953953
not_callable_tys.display(db),
954954
),
@@ -974,7 +974,7 @@ impl<'db> CallOutcome<'db> {
974974
builder.add_diagnostic(
975975
node,
976976
"revealed-type",
977-
format_args!("Revealed type is '{}'.", revealed_ty.display(db)),
977+
format_args!("Revealed type is `{}`", revealed_ty.display(db)),
978978
);
979979
Ok(*return_ty)
980980
}

crates/red_knot_python_semantic/src/types/display.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Display for DisplayType<'_> {
3737
| Type::Class(_)
3838
| Type::Function(_)
3939
) {
40-
write!(f, "Literal[{representation}]",)
40+
write!(f, "Literal[{representation}]")
4141
} else {
4242
representation.fmt(f)
4343
}
@@ -335,7 +335,7 @@ mod tests {
335335
class B: ...
336336
",
337337
)?;
338-
let mod_file = system_path_to_file(&db, "src/main.py").expect("Expected file to exist.");
338+
let mod_file = system_path_to_file(&db, "src/main.py").expect("file to exist");
339339

340340
let union_elements = &[
341341
Type::Unknown,

0 commit comments

Comments
 (0)