diff options
author | 2016-06-23 16:05:50 +0000 | |
---|---|---|
committer | 2016-06-24 08:12:02 +0000 | |
commit | f9c4102eefe81591dc74c94d245c6ba52618d6e5 (patch) | |
tree | f447104e620fae08ad41171e31b1e57661416ee5 /src/main/java/com/google/devtools/build | |
parent | fb040f65cd080d460f65b3294a69b23ec8158460 (diff) |
Improve documentation for type()
--
MOS_MIGRATED_REVID=125683322
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java index 577755e6b4..89c223e2fb 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java @@ -2101,15 +2101,28 @@ public class MethodLibrary { } }; - @SkylarkSignature(name = "type", returnType = String.class, - doc = "Returns the type name of its argument.", - parameters = {@Param(name = "x", doc = "The object to check type of.")}) - private static final BuiltinFunction type = new BuiltinFunction("type") { - public String invoke(Object object) { - // There is no 'type' type in Skylark, so we return a string with the type name. - return EvalUtils.getDataTypeName(object, false); - } - }; + @SkylarkSignature( + name = "type", + returnType = String.class, + doc = + "Returns the type name of its argument. This is useful for debugging and " + + "type-checking. Examples:" + + "<pre class=\"language-python\">" + + "type(2) == \"int\"\n" + + "type([1]) == \"list\"\n" + + "type(struct(a = 2)) == \"struct\"\n" + + "</pre>" + + "To write Python-compatible code, you can compare the return values: " + + "<code>if type(x) == type([])</code>.", + parameters = {@Param(name = "x", doc = "The object to check type of.")} + ) + private static final BuiltinFunction type = + new BuiltinFunction("type") { + public String invoke(Object object) { + // There is no 'type' type in Skylark, so we return a string with the type name. + return EvalUtils.getDataTypeName(object, false); + } + }; @SkylarkSignature( name = "fail", |