On this page
  1. ast.copy_location
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

ast.copy_location

Prev: ast.compare | Up: ast | Next: ast.dump
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.copy_location
Tags: #public #python3 #stdlib #ast


Import

import ast
from ast import copy_location

Signature & Overview

ast.copy_location(new_node, old_node)

Copy source location (lineno, col_offset, end_lineno, and end_col_offset attributes) from old_node to new_node if possible, and return new_node.

Usage

import ast

old = ast.parse("1", mode="eval").body
new = ast.copy_location(ast.Constant(2), old)
assert new.lineno == old.lineno and new.col_offset == old.col_offset

Gotchas

REPL Inspect

from ast import copy_location
help(copy_location)

Linked from

Related notes