Skip to content

Productivity Actions

This category collects BetterPy features that streamline common editing and navigation workflows, helping you move faster through everyday Python tasks.


Copy Actions

Copy with imports

Since 2026.06.0 · Maturity Incubating · Issues PY-62801

Copy with imports copies the selected Python code and prepends the import statements that are referenced inside that selection.

How to use it

Select Python code, then run Edit | Copy Special | Copy with Imports.

import typing as t
from pydantic import BaseModel

class Model(BaseModel):
    field: t.Annotated[int, None]
import typing as t
from pydantic import BaseModel

class Model(BaseModel):
    field: t.Annotated[int, None]

Notes

  • The selected text is copied as-is, with only trailing whitespace trimmed.
  • Import statements already inside the selection are not duplicated.
  • The feature is gated by the Copy with imports setting under Settings | BetterPy | Productivity Actions | Copying.

Generate Actions

Generate class actions

Since 2026.04.13 · Maturity Stable

Use BetterPy's Generate menu entries to scaffold common Python class shapes without leaving the editor. Each action inserts the class at the caret, adds any required imports, and starts a live template for editing the generated declaration in place.

Available generators

  • dataclass inserts a plain @dataclass.
  • pytest test class inserts a pytest class with one test, named from the first configured python_classes and python_functions patterns.
  • frozen dataclass (kw_only) inserts @dataclass(frozen=True, kw_only=True).
  • pydantic model (with config) inserts a BaseModel plus an empty ConfigDict().

How it behaves

  • The actions are available from Code | Generate (⌘N / Alt+Insert) in Python files.
  • The test-class action appears only when the current module or containing class matches the configured pytest collection naming. It uses the first configured class and function pattern when multiple patterns are present.
  • Test classes are always inserted at module scope so pytest can discover them.
  • Other generated classes are inserted into the surrounding class with matching indentation when the caret is inside a class body.
  • When the file is missing imports such as dataclass, BaseModel, or ConfigDict, BetterPy adds them without duplicating existing imports.
  • After insertion, use Tab to move through the live-template fields. Test classes expose the editable class and method name stems plus the test body; the other generators expose the class name and body.

Examples

class TestClass:
    def test_method(self):
        assert False, "Not implemented"
from dataclasses import dataclass


@dataclass
class NewDataclass:
    pass
from dataclasses import dataclass


@dataclass(frozen=True, kw_only=True)
class NewFrozenDataclass:
    pass
from pydantic import BaseModel, ConfigDict


class NewModel(BaseModel):
    model_config = ConfigDict()
    pass

Placement rules

If the caret is between existing statements, BetterPy inserts the generated class at that position instead of always appending it to the end of the file. That makes it practical to scaffold nested helper classes exactly where you want them.


Run Configuration

UV script runner & debugger

Since 2026.08.5 · Maturity Stable · Issues PY-88510

Run and debug [project.scripts] and [project.gui-scripts] entry points in uv projects directly from pyproject.toml or the Run menu. BetterPy keeps matching Python run configurations in sync so scripts stay available in the Run dropdown.

Overview

When working with uv Python projects, entry points are declared in pyproject.toml:

[project.scripts]
mytool = "mypackage.cli:main"

[project.gui-scripts]
myapp = "mypackage.gui:start"

BetterPy automatically parses entry points and provides:

  • Gutter Run Icons: Click green play icons next to valid entry point declarations in pyproject.toml. Empty or unresolved targets do not get an icon.
  • Run Configurations: Detected scripts get a workspace-local uv: <script> configuration. Existing or customized configs for the same script are reused and never overwritten. Plugin-owned configs are removed when a script is commented out or deleted.
  • Run & Debug Actions: Execute scripts directly with the Python debugger (pydevd) attached.
  • Context Menu Actions: Right-click entry points in pyproject.toml to run or debug.
  • Search & Quick Picker: UV: Debug / Run Project Script... search menu with argument prompts.
  • Last Run Re-execution: UV: Debug / Re-run Last Script to instantly re-run your previous script.
  • Generate Entry Point: When pyproject.toml has no [project.scripts] mapping, use Generate → uv: script entry point to insert it with a live-template key and an empty target string.

Quick Start

  1. Open a pyproject.toml file.
  2. If it has no [project.scripts] mapping, choose Generate → uv: script entry point. Otherwise, skip to step 4.
  3. Fill in the script name and target in the live template.
  4. Click the green play icon in the gutter next to the entry point name.
  5. Select Run or Debug.

Documentation Enhancements

Inherited Attribute Documentation

Since 2026.07.0 · Maturity Incubating

Show an ancestor attribute's docstring in Quick Documentation when a subclass overrides the attribute without adding local documentation. PyCharm renders direct attribute docstrings natively; BetterPy only fills the inherited override gap.

How to invoke

Place the caret on an overriding class attribute and open Quick Documentation with F1 / Ctrl+Q or the usual editor documentation action.

Example

class HttpUser:
    tasks = []
    """Collection of task classes that this user will run."""


class BooksAPI(HttpUser):
    tasks = [CrudFlow]

Quick Documentation for BooksAPI.tasks keeps PyCharm's native BooksAPI header and shows the documentation inherited from HttpUser.tasks.

Notes

  • A local attribute docstring always takes precedence and is rendered by PyCharm.
  • Example-bearing inherited docstrings are handed to the separate Docstring Example Rendering feature.
  • Existing Attribute Docstring in Quick Documentation preferences are migrated once to this feature.

Docstring Example Rendering

Since 2026.06.0 · Maturity Incubating · Issues PY-47744

Renders doctests and fenced Python examples in Quick Documentation for Python docstrings, so runnable examples are easier to scan and copy.

How to invoke: F1 / Ctrl+Q on a documented function, class, or module.

def normalize_name(value: str) -> str:
    """
    Normalize a display name.

    Examples:
        >>> normalize_name(" Ada ")
        'ada'
    """
    return value.strip().lower()
>>> normalize_name(" Ada ")
'ada'

Notes

  • Doctest prompts and fenced Python blocks are rendered as Python code blocks.
  • The rendered example includes a copy link that copies only executable input for doctest snippets.
  • The feature is gated by the Docstring Example Rendering setting under Settings | BetterPy | Productivity Actions | Documentation.