{"record":{"id":"04fac3b30e1887bd","repo":"bazelbuild/bazel","slug":"isinstance-is-not-yet-supported","errorCode":null,"errorMessage":"isinstance() is not yet supported","messagePattern":"isinstance\\(\\) is not yet supported","errorType":"exception","errorClass":"EvalException","httpStatus":null,"severity":"error","filePath":"src/main/java/net/starlark/java/eval/Eval.java","lineNumber":596,"sourceCode":"    // expressions; see b/153764542.\n    switch (expr.kind()) {\n      case BINARY_OPERATOR:\n        return evalBinaryOperator(fr, (BinaryOperatorExpression) expr);\n      case COMPREHENSION:\n        return evalComprehension(fr, (Comprehension) expr);\n      case CONDITIONAL:\n        return evalConditional(fr, (ConditionalExpression) expr);\n      case DICT_EXPR:\n        return evalDict(fr, (DictExpression) expr);\n      case DOT:\n        return evalDot(fr, (DotExpression) expr);\n      case CALL:\n        return evalCall(fr, (CallExpression) expr);\n      case CAST:\n        return eval(fr, ((CastExpression) expr).getValue());\n      case ISINSTANCE:\n        fr.setErrorLocation(expr.getStartLocation());\n        throw new EvalException(\"isinstance() is not yet supported\");\n      case IDENTIFIER:\n        return evalIdentifier(fr, (Identifier) expr);\n      case INDEX:\n        return evalIndex(fr, (IndexExpression) expr);\n      case INT_LITERAL:\n        // TODO(adonovan): opt: avoid allocation by saving\n        // the StarlarkInt in the IntLiteral (a temporary hack\n        // until we use a compiled representation).\n        Number n = ((IntLiteral) expr).getValue();\n        if (n instanceof Integer nInt) {\n          return StarlarkInt.of(nInt);\n        } else if (n instanceof Long nLong) {\n          return StarlarkInt.of(nLong);\n        } else {\n          return StarlarkInt.of((BigInteger) n);\n        }\n      case FLOAT_LITERAL:\n        return StarlarkFloat.of(((FloatLiteral) expr).getValue());","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/net/starlark/java/eval/Eval.java#L578-L614","documentation":"The parser of this Starlark dialect can produce an ISINSTANCE expression node (isinstance(x, T)), but the evaluator does not implement it: evaluating such a node sets the error location and immediately throws EvalException 'isinstance() is not yet supported'. So even though the syntax parses, it can never run in this interpreter version.","triggerScenarios":"Evaluating any script containing isinstance(...) under this interpreter build; code ported from python or from a Starlark dialect (e.g. with the isinstance extension enabled in the parser) run on an evaluator lacking the feature.","commonSituations":"Porting Python validation code to .bzl/Starlark; enabling parser extensions that accept isinstance syntax; version differences between Starlark dialects (one supports it, another only parses it).","solutions":["Replace isinstance() with a type check that is supported: type(x) == type(y), x == True for booleans, hasattr(x, 'attr') for capability checks, or type(x).name comparisons.","Restructure to avoid type dispatch (use different methods or fail-fast validation of expected value kinds).","If isinstance semantics are required, move the check into a native Java builtin."],"exampleFix":"# before\nif isinstance(v, string): process(v)\n\n# after\nif type(v) == type(\"\"): process(v)","handlingStrategy":"validation","validationCode":"# Reject isinstance before evaluation (simple textual check for toolchains)\nif grep -qnE '\\bisinstance\\s*\\(' script.star; then\n  echo \"isinstance() is not supported by this interpreter; use type(x) == type(y)\" >&2\n  exit 2\nfi","typeGuard":"# Starlark replacement helper (in a .bzl file)\ndef is_string(x):\n    return type(x) == type(\"\")\n\ndef is_list(x):\n    return type(x) == type([])","tryCatchPattern":null,"preventionTips":["Do not port Python isinstance() calls into Starlark; translate them to type() comparisons.","Lint repositories for 'isinstance(' as part of CI for Starlark files.","Prefer hasattr() capability checks over type checks for Starlark values."],"tags":["starlark","interpreter","unsupported-feature","python-compat"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}