{"record":{"id":"48645256fb7a155f","repo":"nodejs/node","slug":"can-t-create-internal-names-use-the-free-identi","errorCode":null,"errorMessage":"Can't create internal names.  Use the `free_identifier` method on a parser.","messagePattern":"Can't create internal names\\.  Use the `free_identifier` method on a parser\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/nodes.py","lineNumber":904,"sourceCode":"    \"\"\"If created with an import name the import name is returned on node\n    access.  For example ``ImportedName('cgi.escape')`` returns the `escape`\n    function from the cgi module on evaluation.  Imports are optimized by the\n    compiler so there is no need to assign them to local variables.\n    \"\"\"\n    fields = ('importname',)\n\n\nclass InternalName(Expr):\n    \"\"\"An internal name in the compiler.  You cannot create these nodes\n    yourself but the parser provides a\n    :meth:`~jinja2.parser.Parser.free_identifier` method that creates\n    a new identifier for you.  This identifier is not available from the\n    template and is not threated specially by the compiler.\n    \"\"\"\n    fields = ('name',)\n\n    def __init__(self):\n        raise TypeError('Can\\'t create internal names.  Use the '\n                        '`free_identifier` method on a parser.')\n\n\nclass MarkSafe(Expr):\n    \"\"\"Mark the wrapped expression as safe (wrap it as `Markup`).\"\"\"\n    fields = ('expr',)\n\n    def as_const(self, eval_ctx=None):\n        eval_ctx = get_eval_context(self, eval_ctx)\n        return Markup(self.expr.as_const(eval_ctx))\n\n\nclass MarkSafeIfAutoescape(Expr):\n    \"\"\"Mark the wrapped expression as safe (wrap it as `Markup`) but\n    only if autoescaping is active.\n\n    .. versionadded:: 2.5\n    \"\"\"","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/nodes.py#L886-L922","documentation":"Raised by jinja2.nodes.InternalName.__init__ to forbid external construction of InternalName AST nodes. InternalName represents compiler-allocated scratch variables produced only by Parser.free_identifier(); allowing user code to mint them would break the compiler's identifier tracking. The constructor unconditionally raises TypeError.","triggerScenarios":"Calling nodes.InternalName() directly in code that builds or manipulates the Jinja2 AST (e.g. a custom optimizer, transformer, or test harness). Copy/deepcopy of an AST that re-invokes __init__ on an InternalName instance. metaprogramming that enumerates node subclasses and instantiates each.","commonSituations":"Third-party extensions that walk and rebuild the node tree. Test fixtures that try to round-trip every node type. Tools that serialize/deserialize the AST and reconstruct nodes via their __init__.","solutions":["Use parser.free_identifier() on an active Parser instance to obtain a valid InternalName instead of constructing one.","When deep-copying ASTs, special-case InternalName to copy the instance via object.__new__ rather than calling __init__.","In tests, obtain InternalName instances from a real parsed template rather than constructing them.","If you must instantiate for a transform, bypass with object.__new__(nodes.InternalName) and set .name manually - but prefer free_identifier."],"exampleFix":"// before\nnode = nodes.InternalName()\nnode.name = 'tmp_0'\n// after\n# during parsing/transformation with an active parser `parser`\nident = parser.free_identifier()  # returns a fully-formed InternalName","handlingStrategy":"validation","validationCode":"from jinja2 import nodes\n# never call nodes.InternalName() directly; obtain from a parser\n# (placeholder check - real identifiers come from Parser.free_identifier)\nimport inspect\nif inspect.stack()[1].function == '<module>':\n    raise RuntimeError('do not construct InternalName; use parser.free_identifier()')","typeGuard":"def is_internal_name(node) -> bool:\n    return isinstance(node, nodes.InternalName)","tryCatchPattern":"# n/a - construction is a programming error; catch should not mask it\n# fix the call site instead of try/except","preventionTips":["Treat InternalName as parser-internal; never instantiate it from application code.","When deepcopying ASTs, special-case InternalName with copy.copy (which skips __init__).","In test fixtures, parse a real template and traverse the AST rather than constructing nodes."],"tags":["jinja2","ast","internal-name","constructor-guard","parser"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}