Change visibility¶
Toggle a Python symbol between public and private naming without manually renaming the declaration and every call site. BetterPy reuses the IntelliJ rename refactoring, so all references in the project are updated together with the declaration.
How to invoke¶
Place the caret on the name of a function, class, or top-level/class-level variable, then ⌥⏎ / Alt+Enter → "Change visibility: make private" or "Change visibility: make public".
The intention text adapts to the current name:
- A name without a leading underscore offers "make private" and renames name → _name.
- A name starting with _ offers "make public" and strips leading underscores (_name → name, __name → name).
Example¶
What it supports¶
- Functions, classes, and assignment targets (module-level and class-level attributes).
- Updates every reference in the project via the standard rename refactoring, so imports and qualified usages stay in sync.
- Works on names with one or more leading underscores; making a name public removes all of them.
- When invoked on a method that is also defined in a super class or overridden in subclasses, BetterPy asks before changing the rest of the hierarchy. The dialog lists the affected super classes and subclasses and lets you choose between "Rename in Hierarchy", "Rename Only This Method", or "Cancel".
What it deliberately avoids¶
- Dunder names such as
__init__or__call__— these have language-defined semantics. - Pytest test functions (
test_*) and test classes (Test*), since renaming them would hide them from collection. - Symbols defined in
conftest.py, where the_prefix would change pytest fixture discovery. - Names whose target form would collide with a Python reserved keyword.
- Files outside your own project (library or stub sources).
Notes¶
- The intention is gated by the Change visibility setting under Settings | BetterPy | Refactoring & code transformations | Code Transformations and is enabled by default.
- Because the rename runs through
RenameProcessor, conflicts (for example an existing symbol with the target name) are surfaced through the standard refactoring conflict dialog rather than silently overwriting code.