Skip to content

Commit

Permalink
Use backticks for code in red-knot messages (#13599)
Browse files Browse the repository at this point in the history
## 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).
  • Loading branch information
charliermarsh authored Oct 2, 2024
1 parent ef45185 commit c3b40da
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 156 deletions.
4 changes: 2 additions & 2 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn run() -> anyhow::Result<ExitStatus> {
SystemPathBuf::from_path_buf(cwd)
.map_err(|path| {
anyhow!(
"The current working directory '{}' contains non-unicode characters. Red Knot only supports unicode paths.",
"The current working directory `{}` contains non-Unicode characters. Red Knot only supports Unicode paths.",
path.display()
)
})?
Expand All @@ -174,7 +174,7 @@ fn run() -> anyhow::Result<ExitStatus> {
Ok(SystemPath::absolute(cwd, &cli_base_path))
} else {
Err(anyhow!(
"Provided current-directory path '{cwd}' is not a directory."
"Provided current-directory path `{cwd}` is not a directory"
))
}
})
Expand Down
20 changes: 10 additions & 10 deletions crates/red_knot/tests/file_watching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl TestCase {

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

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

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

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

let mut file = std::fs::File::create(absolute_path.as_std_path())
.with_context(|| format!("Failed to open file '{relative_path}'"))?;
.with_context(|| format!("Failed to open file `{relative_path}`"))?;
file.write_all(content.as_bytes())
.with_context(|| format!("Failed to write to file '{relative_path}'"))?;
.with_context(|| format!("Failed to write to file `{relative_path}`"))?;
file.sync_data()?;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ where

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

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

setup_files
.setup(&root_path, &workspace_path)
Expand All @@ -233,7 +233,7 @@ where
}))
{
std::fs::create_dir_all(path.as_std_path())
.with_context(|| format!("Failed to create search path '{path}'"))?;
.with_context(|| format!("Failed to create search path `{path}`"))?;
}

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub(crate) fn resolve_module_query<'db>(
let _span = tracing::trace_span!("resolve_module", %name).entered();

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

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

tracing::trace!(
"Resolved module '{name}' to '{path}'.",
"Resolved module `{name}` to `{path}`",
path = module_file.path(db)
);

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

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

// This query needs to be re-executed each time a `.pth` file
// is added, modified or removed from the `site-packages` directory.
Expand Down
6 changes: 3 additions & 3 deletions crates/red_knot_python_semantic/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl VirtualEnvironment {
} else {
tracing::warn!(
"Failed to resolve `sys.prefix` of the system Python installation \
from the `home` value in the `pyvenv.cfg` file at '{}'. \
from the `home` value in the `pyvenv.cfg` file at `{}`. \
System site-packages will not be used for module resolution.",
venv_path.join("pyvenv.cfg")
);
Expand Down Expand Up @@ -426,7 +426,7 @@ impl Deref for SysPrefixPath {

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

Expand Down Expand Up @@ -483,7 +483,7 @@ impl Deref for PythonHomePath {

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

Expand Down
12 changes: 6 additions & 6 deletions crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fn bindings_ty<'db>(

let first = all_types
.next()
.expect("bindings_ty should never be called with zero definitions and no unbound_ty.");
.expect("bindings_ty should never be called with zero definitions and no unbound_ty");

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

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

let mut conflicting: Vec<Type<'db>> = vec![];
Expand Down Expand Up @@ -917,7 +917,7 @@ impl<'db> CallOutcome<'db> {
node,
"call-non-callable",
format_args!(
"Object of type '{}' is not callable.",
"Object of type `{}` is not callable",
not_callable_ty.display(db)
),
);
Expand All @@ -932,7 +932,7 @@ impl<'db> CallOutcome<'db> {
node,
"call-non-callable",
format_args!(
"Object of type '{}' is not callable (due to union element '{}').",
"Object of type `{}` is not callable (due to union element `{}`)",
called_ty.display(db),
not_callable_ty.display(db),
),
Expand All @@ -948,7 +948,7 @@ impl<'db> CallOutcome<'db> {
node,
"call-non-callable",
format_args!(
"Object of type '{}' is not callable (due to union elements {}).",
"Object of type `{}` is not callable (due to union elements {})",
called_ty.display(db),
not_callable_tys.display(db),
),
Expand All @@ -974,7 +974,7 @@ impl<'db> CallOutcome<'db> {
builder.add_diagnostic(
node,
"revealed-type",
format_args!("Revealed type is '{}'.", revealed_ty.display(db)),
format_args!("Revealed type is `{}`", revealed_ty.display(db)),
);
Ok(*return_ty)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_python_semantic/src/types/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Display for DisplayType<'_> {
| Type::Class(_)
| Type::Function(_)
) {
write!(f, "Literal[{representation}]",)
write!(f, "Literal[{representation}]")
} else {
representation.fmt(f)
}
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
class B: ...
",
)?;
let mod_file = system_path_to_file(&db, "src/main.py").expect("Expected file to exist.");
let mod_file = system_path_to_file(&db, "src/main.py").expect("file to exist");

let union_elements = &[
Type::Unknown,
Expand Down
Loading

0 comments on commit c3b40da

Please sign in to comment.