Skip to content

Commit

Permalink
Update docs for getattr() behavior with a default value
Browse files Browse the repository at this point in the history
Summary: `getattr()` behaves differently depending on the presence of a default value, clarify behavior in the docs.

Reviewed By: ndmitchell, IanChilds

Differential Revision: D57437796

fbshipit-source-id: d06de75f6ffa9f2672f9f2d1d8c86d37c2cf8967
  • Loading branch information
milend authored and facebook-github-bot committed May 16, 2024
1 parent 990a16b commit 5396ff4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions starlark/src/stdlib/funcs/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ pub(crate) fn register_other(builder: &mut GlobalsBuilder) {
///
/// `getattr(x, "f")` is equivalent to `x.f`.
///
/// `getattr(x, "f", d)` is equivalent to `x.f if hasattr(x, "f") else d`
/// and will never raise an error.
///
/// ```
/// # starlark::assert::all_true(r#"
/// getattr("banana", "split")("a") == ["b", "n", "n", ""] # equivalent to "banana".split("a")
Expand Down

0 comments on commit 5396ff4

Please sign in to comment.