> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-codegen-bot-sdk-docs-2-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PyCommentGroup

> A group of related symbols that represent a comment or docstring in Python For example: ``` # Comment 1 # Comment 2 # Comment 3 ``` would be 3 individual comments (accessible via `symbols`), but together they form a `CommentGroup` (accessible via `self`).

export const Attribute = ({type, description}) => <div className="pl-4 py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
      {type}
    </div>
    <p className="mt-2">{description}</p>
  </div>;

export const GithubLinkNote = ({link}) => <Info>
      <div className="flex gap-2 items-center">View Source on <a target="_blank" rel="noopener noreferrer" href={link}>Github</a></div>
   </Info>;

export const HorizontalDivider = ({light = false}) => <div className="divide-y">
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
    </div>;

export const Return = ({return_type, description}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Returns</h4>
    <div className="dark:border-zinc-300/[0.06] ">
        <div className="py-6 first:pt-3 text-sm font-normal">
            <div className="flex gap-4 items-center">
                <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
                    {return_type}
                </div>
            </div>
            <p className="mt-2">{description}</p>
        </div>
    </div>
  </div>;

export const ParameterWrapper = ({children}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Parameters</h4>
    <div className="divide-y dark:border-zinc-300/[0.06]">
      {children}
    </div>
  </div>;

export const Parameter = ({name, type, description, defaultValue}) => <div className="py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="flex justify-between items-start font-mono">
      <div className="flex gap-4 items-start">
        <div className="flex gap-1 items-center text-sm text-primary mt-2">
          {name}
        </div>
        <div className="inline-grid grid-cols-[auto_auto] gap-1 py-2">
          {type}
        </div>
      </div>

      <div className="flex-shrink-0 mt-2">
        {defaultValue ? <div className="flex gap-1 items-center text-sm border border-purple-500 px-2 py-0.5 rounded">
            <span className="text-zinc-500">default:</span>
            <span className="text-purple-500">{defaultValue}</span>
          </div> : <span className="text-sm border border-purple-500 px-2 py-0.5 rounded">
            required
          </span>}
      </div>
    </div>
    <p className="mt-2">{description}</p>
  </div>;

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/python/symbol_groups/comment_group.py#L23-L250" />

### Inherits from

[CommentGroup](/api-reference/core/CommentGroup), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable)

## Attributes

<HorizontalDivider />

### <span className="text-primary">extended</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/SymbolGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SymbolGroup</a></> } description="Returns a SymbolGroup of all extended nodes associated with this element." />

### <span className="text-primary">extended\_source</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the source text representation of all extended nodes." />

### <span className="text-primary">file</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyFile</a></> } description="The file object that this Editable instance belongs to." />

### <span className="text-primary">filepath</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The file path of the file that this Editable instance belongs to." />

### <span className="text-primary">function\_calls</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/FunctionCall" style={ {fontWeight: "inherit", fontSize: "inherit"} }>FunctionCall</a> <span>]</span></> } description="Returns a list of all function calls contained within this expression." />

### <span className="text-primary">next\_named\_sibling</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="Returns the next named sibling of the last symbol in the group." />

### <span className="text-primary">next\_sibling</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="Returns the next sibling of the last symbol in the symbol group." />

### <span className="text-primary">parent</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a></> } description="The parent node of this Editable instance." />

### <span className="text-primary">parent\_class</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyClass" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyClass</a> <span>| None</span></> } description="Find the class this node is contained in" />

### <span className="text-primary">parent\_function</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyFunction" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyFunction</a> <span>| None</span></> } description="Find the function this node is contained in" />

### <span className="text-primary">parent\_statement</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Statement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Statement</a> <span>| None</span></> } description="Find the statement this node is contained in" />

### <span className="text-primary">source</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the concatenated source code of all symbols in the group." />

### <span className="text-primary">symbols</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="Returns the list of symbols in the group." />

### <span className="text-primary">text</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Return the text content of all comments in the comment block." />

### <span className="text-primary">variable\_usages</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" />

## Methods

<HorizontalDivider />

### <span className="text-primary">ancestors</span>

Find all ancestors of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1119-L1127" />

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="" />

### <span className="text-primary">edit</span>

Replace the source of this node with new text.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L221-L237" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new source text to replace the current text with." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." defaultValue="False" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Prevents duplicate edits at the same location. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">edit\_text</span>

Replace the text content of a comment group with new text.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_groups/comment_group.py#L57-L74" />

<ParameterWrapper>
  <Parameter name="new_text" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new text content to replace the existing comment text." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">find</span>

Search for substrings in the given symbols that match `strings_to_match`.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L155-L165" />

<ParameterWrapper>
  <Parameter name="strings_to_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">list[str] | str</code> } description="The string or list of strings to search for." defaultValue="" />

  <Parameter name="exact" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, only return nodes that exactly match the query." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects representing each match found." />

### <span className="text-primary">find\_string\_literals</span>

Search for string literals matching given strings in the SymbolGroup.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L123-L136" />

<ParameterWrapper>
  <Parameter name="strings_to_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">list[str]</code> } description="List of strings to search for in string literals." defaultValue="" />

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="If True, performs fuzzy matching instead of exact matching." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="List of Editable nodes representing the matching string literals found within the symbols." />

### <span className="text-primary">flag</span>

Adds a visual flag comment to the end of this Editable's source text.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L939-L950" />

<Return return_type={ <><span>CodeFlag[</span> <a href="/api-reference/python/PyCommentGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCommentGroup</a> <span>]</span></> } description="" />

### <span className="text-primary">get\_variable\_usages</span>

Returns Editables for all TreeSitter nodes corresponding to instances of variable usage

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L909-L925" />

<ParameterWrapper>
  <Parameter name="var_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The variable name to search for." defaultValue="" />

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>Sequence[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>[</span> <a href="/api-reference/python/PyCommentGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCommentGroup</a> <span>]]</span></> } description="List of Editable objects representing variable usage nodes matching the given name." />

### <span className="text-primary">insert\_after</span>

Inserts source code after this node in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L202-L218" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The source code to insert." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Adjust indentation to match current text." defaultValue="False" />

  <Parameter name="newline" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Add a newline before the inserted code." defaultValue="True" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Priority of the edit operation." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Deduplicate identical edits." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">insert\_before</span>

Inserts source code before this symbol group.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L184-L199" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The source code to insert." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." defaultValue="False" />

  <Parameter name="newline" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to add a newline after the inserted code. Defaults to True." defaultValue="True" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to prevent duplicate insertions of the same code. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">is\_child\_of</span>

Checks if this node is a descendant of the given editable instance in the AST.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1109-L1116" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="" />

### <span className="text-primary">is\_wrapped\_in</span>

Check if this node is contained another node of the given class

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1088-L1090" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="" />

### <span className="text-primary">parent\_of\_type</span>

Find the first ancestor of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1093-L1099" />

<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="" />

### <span className="text-primary">parent\_of\_types</span>

Find the first ancestor of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1101-L1107" />

<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="" />

### <span className="text-primary">reduce\_condition</span>

Reduces an editable to the following condition

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1044-L1049" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">remove</span>

Removes this node and its related extended nodes from the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L240-L252" />

<ParameterWrapper>
  <Parameter name="delete_formatting" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to delete related extended nodes like decorators and comments. Defaults to True." defaultValue="True" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Priority level of the removal operation. Defaults to 0." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to deduplicate removal operations. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">replace</span>

Replaces all instances of a string with a new string in all symbols within the group.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L139-L152" />

<ParameterWrapper>
  <Parameter name="old" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The string to be replaced." defaultValue="" />

  <Parameter name="new" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The string to replace with." defaultValue="" />

  <Parameter name="count" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Maximum number of replacements to make. Defaults to -1 (replace all)." defaultValue="-1" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Priority of the replacement operation. Defaults to 0." defaultValue="0" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="Number of replacements made." />

### <span className="text-primary">search</span>

Searches for regex matches in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/symbol_group.py#L168-L181" />

<ParameterWrapper>
  <Parameter name="regex_pattern" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The regular expression pattern to search for." defaultValue="" />

  <Parameter name="include_strings" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to include string literals in the search. Defaults to True." defaultValue="True" />

  <Parameter name="include_comments" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to include comments in the search. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects representing matched text nodes in the codebase." />

### <span className="text-primary">to\_google\_docstring</span>

Convert a comment group into a Google-style docstring.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/python/symbol_groups/comment_group.py#L100-L245" />

<ParameterWrapper>
  <Parameter name="function" type={ <><a href="/api-reference/python/PyFunction" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyFunction</a></> } description="The Python function whose signature will be used to extract parameter and return type information." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="A formatted Google-style docstring string that includes the function's description, parameters, and return value information." />
